(trackId: string)
| 118 | } |
| 119 | |
| 120 | export async function getTrack(trackId: string) { |
| 121 | const value: Tracks = await cache.get("Track", [trackId.toString()]); |
| 122 | if (value) { |
| 123 | return { |
| 124 | ...value, |
| 125 | problems: value.problems.map((problem: { problem: Problem }) => ({ ...problem.problem })), |
| 126 | }; |
| 127 | } |
| 128 | try { |
| 129 | const track = await db.track.findUnique({ |
| 130 | where: { |
| 131 | id: trackId, |
| 132 | }, |
| 133 | include: { |
| 134 | problems: { |
| 135 | select: { |
| 136 | problem: true, |
| 137 | }, |
| 138 | orderBy: [ |
| 139 | { |
| 140 | sortingOrder: "desc", |
| 141 | }, |
| 142 | ], |
| 143 | }, |
| 144 | }, |
| 145 | }); |
| 146 | if (track) { |
| 147 | await cache.set("Track", [trackId.toString()], track); |
| 148 | return { |
| 149 | ...track, |
| 150 | problems: track.problems.map((problem: any) => ({ ...problem.problem })), |
| 151 | }; |
| 152 | } |
| 153 | return null; |
| 154 | } catch (err) { |
| 155 | return null; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | export async function getAllTracks() { |
| 160 | const value = await cache.get("getAllTracks", []); |
no test coverage detected