day len server theo loi Khoi noi, toi xin tuyen bo mien tru trach nhiem

This commit is contained in:
2024-11-05 15:02:53 +07:00
parent 0f68b51d75
commit 56ba2808c8
22 changed files with 482 additions and 63 deletions

View File

@@ -159,14 +159,14 @@ export class ServiceSchema extends PothosSchema {
throw new Error('Not allowed')
}
// check role if user is mentor or center owner
const role = ctx.http.me.role
const role = ctx.http.me?.role
if (role !== Role.CENTER_MENTOR && role !== Role.CENTER_OWNER) {
throw new Error('Not allowed')
}
if (role === Role.CENTER_MENTOR) {
// load only service belong to center of current user
const managedServices = await this.prisma.managedService.findMany({
where: { mentorId: ctx.http.me.id },
where: { mentorId: ctx.http.me?.id ?? '' },
})
if (!managedServices) {
throw new Error('Managed services not found')
@@ -179,7 +179,7 @@ export class ServiceSchema extends PothosSchema {
// if role is center owner, load all services belong to center of current user
if (role === Role.CENTER_OWNER) {
const center = await this.prisma.center.findUnique({
where: { centerOwnerId: ctx.http.me.id },
where: { centerOwnerId: ctx.http.me?.id ?? '' },
})
if (!center) {
throw new Error('Center not found')
@@ -234,7 +234,7 @@ export class ServiceSchema extends PothosSchema {
throw new Error('Not allowed')
}
// replace userId with current user id
args.input.user = { connect: { id: ctx.http.me.id } }
args.input.user = { connect: { id: ctx.http.me?.id ?? '' } }
return await this.prisma.service.create({
...query,
data: args.input,
@@ -321,7 +321,7 @@ export class ServiceSchema extends PothosSchema {
adminNote: {
create: {
content: args.adminNote ?? '',
notedByUserId: ctx.http.me.id,
notedByUserId: ctx.http.me?.id ?? '',
},
},
},