Skip to content

Commit

Permalink
Merge pull request #397 from vevcom/feat/userAPI
Browse files Browse the repository at this point in the history
feat/get User API endpoint
  • Loading branch information
theodorklauritzen authored Feb 20, 2025
2 parents 0cfd399 + 1fecafb commit 38a3f20
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 8 deletions.
2 changes: 0 additions & 2 deletions src/app/api/shop/getAll/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use server'

import { apiHandler } from '@/app/api/apiHandler'
import { readShops } from '@/services/shop/shop/read'

Expand Down
2 changes: 0 additions & 2 deletions src/app/api/shop/product/barcode/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use server'

import { apiHandler } from '@/app/api/apiHandler'
import { readProductByBarCode } from '@/services/shop/product/read'

Expand Down
1 change: 0 additions & 1 deletion src/app/api/shop/purchase/createByStudentCard/route.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use server'
import { apiHandler } from '@/app/api/apiHandler'
import { createPurchaseByStudentCard } from '@/services/shop/purchase/create'

Expand Down
2 changes: 0 additions & 2 deletions src/app/api/users/connectStudentCard/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use server'

import { apiHandler } from '@/api/apiHandler'
import { connectStudentCard } from '@/services/users/update'

Expand Down
10 changes: 10 additions & 0 deletions src/app/api/users/getWithBalance/[studentCard]/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { apiHandler } from '@/api/apiHandler'
import { readUserWithBalance } from '@/services/users/read'


export const GET = apiHandler({
params: (rawparams: { studentCard: string }) => ({
studentCard: rawparams.studentCard,
}),
serviceMethod: readUserWithBalance,
})
2 changes: 1 addition & 1 deletion src/services/shop/purchase/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export const createPurchaseByStudentCard = ServiceMethod({
// TODO: Return remaining balance in account

return {
remainingBalance: 15100,
remainingBalance: 191900,
user,
productList,
}
Expand Down
25 changes: 25 additions & 0 deletions src/services/users/read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,31 @@ export async function readUserOrNull(where: readUserWhere): Promise<User | null>
return await prismaCall(() => prisma.user.findFirst({ where }))
}

export const readUserWithBalance = ServiceMethod({
auther: ({ params }) => readUserAuther.dynamicFields({
username: params.username || '',
}),
paramsSchema: z.object({
username: z.string().optional(),
id: z.number().optional(),
email: z.string().optional(),
studentCard: z.string().optional(),
}),
method: async ({ prisma: prisma_, params }) => {
const user = await prisma_.user.findFirstOrThrow({
where: params,
include: {
image: true,
}
})

return {
balance: 191900,
user,
}
}
})

export const readUserProfile = ServiceMethod({
paramsSchema: z.object({
username: z.string(),
Expand Down

0 comments on commit 38a3f20

Please sign in to comment.