This repository has been archived by the owner on Sep 25, 2023. It is now read-only.
generated from trpc/examples-next-prisma-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from soulsam480/student-views/feat/basics-scor…
…e-education Student views/feat/basics score education
- Loading branch information
Showing
52 changed files
with
2,352 additions
and
946 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { createRouter } from '../../createRouter' | ||
import { z } from 'zod' | ||
import { createStudentBasicsSchema } from '@mirai/app' | ||
import { TRPCError } from '@trpc/server' | ||
|
||
export const basicsRouter = createRouter() | ||
.query('get', { | ||
input: z.number(), | ||
async resolve({ ctx, input }) { | ||
const studentBasics = await ctx.prisma.studentBasics.findFirst({ | ||
where: { studentId: input }, | ||
}) | ||
|
||
if (studentBasics === null) { | ||
throw new TRPCError({ | ||
code: 'NOT_FOUND', | ||
message: 'Student basics not found !', | ||
}) | ||
} | ||
|
||
return studentBasics | ||
}, | ||
}) | ||
.mutation('manage', { | ||
input: createStudentBasicsSchema, | ||
async resolve({ ctx, input }) { | ||
const { studentId, ...data } = input | ||
const result = await ctx.prisma.studentBasics.upsert({ | ||
where: { studentId }, | ||
create: input, | ||
update: data, | ||
}) | ||
|
||
return result | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { createStudentEducationSchema } from '@mirai/app' | ||
import { TRPCError } from '@trpc/server' | ||
import { z } from 'zod' | ||
import { createRouter } from '../../createRouter' | ||
|
||
export const educationRouter = createRouter() | ||
.mutation('create', { | ||
input: createStudentEducationSchema, | ||
async resolve({ ctx, input }) { | ||
const result = await ctx.prisma.studentEducation.createMany({ | ||
data: input, | ||
}) | ||
|
||
return result | ||
}, | ||
}) | ||
.mutation('update', { | ||
input: createStudentEducationSchema.omit({ studentId: true }).partial().extend({ id: z.number() }), | ||
async resolve({ ctx, input }) { | ||
const { id, ...data } = input | ||
const result = await ctx.prisma.studentEducation.update({ | ||
where: { id }, | ||
data, | ||
}) | ||
|
||
return result | ||
}, | ||
}) | ||
.mutation('remove', { | ||
input: z.number(), | ||
async resolve({ ctx, input }) { | ||
try { | ||
await ctx.prisma.studentEducation.delete({ where: { id: input } }) | ||
} catch (error) { | ||
throw new TRPCError({ code: 'INTERNAL_SERVER_ERROR', message: 'Unable to delete experience' }) | ||
} | ||
}, | ||
}) | ||
.query('get_all', { | ||
input: z.number(), | ||
async resolve({ ctx, input }) { | ||
const educationDetails = await ctx.prisma.studentEducation.findMany({ | ||
where: { studentId: input }, | ||
}) | ||
|
||
if (educationDetails === null) { | ||
throw new TRPCError({ | ||
code: 'NOT_FOUND', | ||
message: 'Student education details not found !', | ||
}) | ||
} | ||
return educationDetails | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { createRouter } from '../../createRouter' | ||
import { z } from 'zod' | ||
import { TRPCError } from '@trpc/server' | ||
import { semUpdateSchema } from '@mirai/app' | ||
|
||
export const scoreRouter = createRouter() | ||
.query('get', { | ||
input: z.number(), | ||
async resolve({ ctx, input }) { | ||
const scoreDetails = await ctx.prisma.studentScore.findFirst({ | ||
where: { studentId: input }, | ||
}) | ||
|
||
if (scoreDetails === null) { | ||
throw new TRPCError({ | ||
code: 'NOT_FOUND', | ||
message: 'Student score details not found !', | ||
}) | ||
} | ||
|
||
return scoreDetails | ||
}, | ||
}) | ||
.mutation('update_score_card', { | ||
input: z.object({ studentId: z.number(), data: z.record(semUpdateSchema) }), | ||
async resolve({ ctx, input: { data, studentId } }) { | ||
const scoreData = await ctx.prisma.studentScore.update({ | ||
where: { studentId }, | ||
data: { | ||
scores: data, | ||
}, | ||
}) | ||
|
||
return scoreData | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.