Refactor CollaborationSession and Document schemas to improve code clarity and functionality. Enhance error handling in collaboration session retrieval and update logic. Introduce new request sync events in Document schema and update Minio service for document page management. Adjust cron job to use current date for future schedule date checks. Update user schema for better error handling and improve service descriptions in order schema. Remove global decorators from Workshop modules for better module encapsulation.
This commit is contained in:
@@ -1,22 +1,11 @@
|
||||
import { Inject, Injectable, Logger } from '@nestjs/common'
|
||||
import {
|
||||
Pothos,
|
||||
PothosRef,
|
||||
PothosSchema,
|
||||
SchemaBuilderToken,
|
||||
} from '@smatch-corp/nestjs-pothos'
|
||||
import { Pothos, PothosRef, PothosSchema, SchemaBuilderToken } from '@smatch-corp/nestjs-pothos'
|
||||
import { Builder, SchemaContext } from '../Graphql/graphql.builder'
|
||||
import { PrismaService } from '../Prisma/prisma.service'
|
||||
import { clerkClient } from '@clerk/express'
|
||||
import { MailService } from '../Mail/mail.service'
|
||||
import { MessageSchema } from 'src/Message/message.schema'
|
||||
import {
|
||||
ChatRoom,
|
||||
Message,
|
||||
MessageContextType,
|
||||
MessageType,
|
||||
Role,
|
||||
} from '@prisma/client'
|
||||
import { ChatRoom, Message, MessageContextType, MessageType, Role } from '@prisma/client'
|
||||
import { PubSubEvent } from 'src/common/pubsub/pubsub-event'
|
||||
import { DateTimeUtils } from 'src/common/utils/datetime.utils'
|
||||
import { ChatroomSchema } from '../ChatRoom/chatroom.schema'
|
||||
@@ -245,8 +234,7 @@ export class UserSchema extends PothosSchema {
|
||||
}),
|
||||
|
||||
users: t.prismaField({
|
||||
description:
|
||||
'Retrieve a list of users with optional filtering, ordering, and pagination.',
|
||||
description: 'Retrieve a list of users with optional filtering, ordering, and pagination.',
|
||||
type: [this.user()],
|
||||
args: this.builder.generator.findManyArgs('User'),
|
||||
resolve: async (query, _root, args) => {
|
||||
@@ -265,10 +253,12 @@ export class UserSchema extends PothosSchema {
|
||||
type: this.user(),
|
||||
args: this.builder.generator.findUniqueArgs('User'),
|
||||
resolve: async (query, _root, args) => {
|
||||
return await this.prisma.user.findUniqueOrThrow({
|
||||
const user = await this.prisma.user.findUnique({
|
||||
...query,
|
||||
where: args.where,
|
||||
})
|
||||
if (!user) throw new Error('User not found')
|
||||
return user
|
||||
},
|
||||
}),
|
||||
userBySession: t.prismaField({
|
||||
@@ -378,10 +368,9 @@ export class UserSchema extends PothosSchema {
|
||||
}
|
||||
|
||||
const buffer = Buffer.concat(chunks)
|
||||
const { id: userId, imageUrl } =
|
||||
await clerkClient.users.updateUserProfileImage(id, {
|
||||
file: new Blob([buffer]),
|
||||
})
|
||||
const { id: userId, imageUrl } = await clerkClient.users.updateUserProfileImage(id, {
|
||||
file: new Blob([buffer]),
|
||||
})
|
||||
await this.prisma.user.update({
|
||||
where: { id: userId },
|
||||
data: {
|
||||
@@ -502,10 +491,7 @@ export class UserSchema extends PothosSchema {
|
||||
},
|
||||
})
|
||||
// publish message
|
||||
await ctx.http.pubSub.publish(
|
||||
`${PubSubEvent.NEW_MESSAGE}.${message.recipientId}`,
|
||||
message,
|
||||
)
|
||||
await ctx.http.pubSub.publish(`${PubSubEvent.NEW_MESSAGE}.${message.recipientId}`, message)
|
||||
return message
|
||||
},
|
||||
}),
|
||||
@@ -518,10 +504,7 @@ export class UserSchema extends PothosSchema {
|
||||
if (ctx.isSubscription) {
|
||||
throw new Error('Not allowed')
|
||||
}
|
||||
if (
|
||||
ctx.http.me?.role !== Role.ADMIN &&
|
||||
ctx.http.me?.role !== Role.MODERATOR
|
||||
) {
|
||||
if (ctx.http.me?.role !== Role.ADMIN && ctx.http.me?.role !== Role.MODERATOR) {
|
||||
throw new Error(`Only admin or moderator can ban user`)
|
||||
}
|
||||
if (args.userId === ctx.http.me?.id) {
|
||||
@@ -535,10 +518,7 @@ export class UserSchema extends PothosSchema {
|
||||
throw new Error(`User ${args.userId} not found`)
|
||||
}
|
||||
// if banning user is moderator or admin, throw error
|
||||
if (
|
||||
banningUser.role === Role.MODERATOR ||
|
||||
banningUser.role === Role.ADMIN
|
||||
) {
|
||||
if (banningUser.role === Role.MODERATOR || banningUser.role === Role.ADMIN) {
|
||||
throw new Error(`Cannot ban moderator or admin`)
|
||||
}
|
||||
// ban user from clerk
|
||||
|
||||
Reference in New Issue
Block a user