add centerstaff mutation

This commit is contained in:
2024-10-13 19:38:51 +07:00
parent 1f86786e1a
commit 75a10356da
7 changed files with 99 additions and 25 deletions

View File

@@ -10,7 +10,7 @@ services:
volumes:
- ./src:/app/src
environment:
- NODE_ENV=production
- NODE_ENV=development
- DATABASE_URL=postgresql://your_username:your_password@10.0.27.1:5432/epess
- CLERK_PUBLISHABLE_KEY=pk_test_aW4tY2hpbXAtOTcuY2xlcmsuYWNjb3VudHMuZGV2JA
- CLERK_SECRET_KEY=sk_test_sA5lsb1GHwUNXWQCp5ev70QkaoF5EmdAHNWiCGwZF6
@@ -18,6 +18,9 @@ services:
- LISTEN_PORT=3069
- SWAGGER_PATH=/swagger
- API_PATH=/v1
- MINIO_API_URL=https://objects.epess.org
- MINIO_ACCESS_KEY=71dNgJtzkelXtG3R6IVt
- MINIO_SECRET_KEY=53LmFiDCZxvflJIOsVF9cf0aqkIjNU2oOWtLzGsf
labels:
- 'traefik.enable=true'
- 'traefik.http.routers.api.rule=Host(`api.epess.org`)'

14
package-lock.json generated
View File

@@ -42,6 +42,7 @@
"graphql-tools": "^9.0.1",
"jsonwebtoken": "^9.0.2",
"minio": "^8.0.1",
"nestjs-minio": "^2.6.2",
"passport-jwt": "^4.0.1",
"reflect-metadata": "^0.2.0",
"rxjs": "^7.8.1",
@@ -11865,6 +11866,19 @@
"dev": true,
"license": "MIT"
},
"node_modules/nestjs-minio": {
"version": "2.6.2",
"resolved": "https://registry.npmjs.org/nestjs-minio/-/nestjs-minio-2.6.2.tgz",
"integrity": "sha512-RRrOyt0mZi6VOgm0KZSkeYRnFWMr1z+aaKzmnB/eOwBT11XGjqeY9aNEkPCMjBe+PFd6rethMV+bLtO9YXMsSA==",
"license": "MIT",
"dependencies": {
"minio": "^8.0.1"
},
"peerDependencies": {
"@nestjs/common": ">7.0.0",
"@nestjs/core": ">7.0.0"
}
},
"node_modules/no-case": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/no-case/-/no-case-3.0.4.tgz",

View File

@@ -56,6 +56,7 @@
"graphql-tools": "^9.0.1",
"jsonwebtoken": "^9.0.2",
"minio": "^8.0.1",
"nestjs-minio": "^2.6.2",
"passport-jwt": "^4.0.1",
"reflect-metadata": "^0.2.0",
"rxjs": "^7.8.1",

View File

@@ -49,5 +49,61 @@ export class CenterStaffSchema extends PothosSchema {
},
}),
}));
// mutations
this.builder.mutationFields((t) => ({
createCenterStaff: t.prismaField({
type: this.centerStaff(),
args: {
data: t.arg({
type: this.builder.generator.getCreateInput('CenterStaff'),
required: true,
}),
},
resolve: async (query, root, args, ctx, info) => {
return await this.prisma.centerStaff.create({
...query,
data: args.data,
});
},
}),
updateCenterStaff: t.prismaField({
type: this.centerStaff(),
args: {
where: t.arg({
type: this.builder.generator.getWhereUnique('CenterStaff'),
required: true,
}),
data: t.arg({
type: this.builder.generator.getUpdateInput('CenterStaff'),
required: true,
}),
},
resolve: async (query, root, args, ctx, info) => {
return await this.prisma.centerStaff.update({
...query,
where: args.where,
data: args.data,
});
},
}),
deleteCenterStaff: t.prismaField({
type: this.centerStaff(),
args: {
where: t.arg({
type: this.builder.generator.getWhereUnique('CenterStaff'),
required: true,
}),
},
resolve: async (query, root, args, ctx, info) => {
return await this.prisma.centerStaff.delete({
...query,
where: args.where,
});
},
}),
}));
}
}

View File

@@ -1,9 +1,9 @@
// import { forwardRef, Inject, Injectable } from '@nestjs/common';
// import { Injectable } from '@nestjs/common';
// import { NestMinioService } from 'nestjs-minio';
// import { ConfigService } from '@nestjs/config';
// @Injectable()
// export class MinioService {
// constructor(
// @Inject(forwardRef(() => ConfigService))
// private configService: ConfigService,
// ) {}
// export class MinioService extends NestMinioService {
// constructor(configService: ConfigService) {
// super(configService);
// }
// }

View File

@@ -63,20 +63,23 @@ export class UserSchema extends PothosSchema {
});
},
}),
// userByToken: t.prismaField({
// type: this.user(),
// args: this.builder.args({
// oauthToken: t.arg.string({ required: true }),
// }),
// resolve: async (query, root, args, ctx, info) => {
// // check if the token is valid
// const { user } = await clerkClient.verifyToken
// return await this.prisma.user.findFirst({
// ...query,
// where: args.where,
// });
// },
// }),
userBySession: t.prismaField({
type: this.user(),
args: {
sessionId: t.arg({ type: 'String', required: true }),
},
resolve: async (query, root, args, ctx, info) => {
// check if the token is valid
const session = await clerkClient.sessions.getSession(args.sessionId);
console.log(session);
return await this.prisma.user.findFirst({
...query,
where: {
id: session.userId,
},
});
},
}),
}));
// Mutation section

View File

@@ -25,9 +25,6 @@ async function bootstrap() {
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup(process.env.SWAGGER_PATH ?? 'v1', app, document);
console.log(process.env.API_PATH);
document.paths[process.env.API_PATH + '/graphql'] = {
get: {