Enhance NestJS application with SWC builder configuration, add @nestjs/devtools-integration for development support, and refactor various components for improved readability. Update package dependencies and streamline import statements across multiple files.

This commit is contained in:
2024-11-26 04:26:55 +07:00
parent c4e302387f
commit a1ca5c62fb
12 changed files with 1646 additions and 235 deletions

View File

@@ -1,10 +1,5 @@
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 { DocumentEvent } from './document.event'
@@ -99,10 +94,7 @@ export class DocumentSchema extends PothosSchema {
...query,
orderBy: args.orderBy ?? undefined,
where: {
OR: [
{ ownerId: ctx.http.me.id },
{ collaborators: { some: { userId: ctx.http.me.id } } },
],
OR: [{ ownerId: ctx.http.me.id }, { collaborators: { some: { userId: ctx.http.me.id } } }],
},
})
},
@@ -138,11 +130,7 @@ export class DocumentSchema extends PothosSchema {
if (ctx.isSubscription) throw new Error('Not allowed')
const userId = ctx.http?.me?.id
if (!userId) throw new Error('User not found')
const fileUrl = await this.minio.getFileUrl(
'document',
'document',
'document',
)
const fileUrl = await this.minio.getFileUrl('document', 'document', 'document')
if (!fileUrl) throw new Error('File not found')
const document = await this.prisma.document.create({
...query,
@@ -211,10 +199,7 @@ export class DocumentSchema extends PothosSchema {
delta,
senderId: ctx.http?.me?.id,
}
ctx.http.pubSub.publish(
`${DocumentEvent.CHANGED}.${args.documentId}`,
documentDelta,
)
ctx.http.pubSub.publish(`${DocumentEvent.CHANGED}.${args.documentId}`, documentDelta)
return documentDelta
},
}),
@@ -275,9 +260,7 @@ export class DocumentSchema extends PothosSchema {
if (
document.ownerId !== ctx.http?.me?.id &&
!document.isPublic &&
!document.collaborators.some(
(c) => c.userId === ctx.http?.me?.id && c.writable,
)
!document.collaborators.some((c) => c.userId === ctx.http?.me?.id && c.writable)
)
throw new Error('User is not owner or collaborator of document')
return await this.prisma.document.update({
@@ -302,8 +285,7 @@ export class DocumentSchema extends PothosSchema {
where: { id: args.documentId },
})
if (!document) throw new Error('Document not found')
if (document.ownerId !== ctx.http?.me?.id)
throw new Error('User is not owner of document')
if (document.ownerId !== ctx.http?.me?.id) throw new Error('User is not owner of document')
return await this.prisma.documentCollaborator.create({
data: {
documentId: args.documentId,
@@ -342,17 +324,16 @@ export class DocumentSchema extends PothosSchema {
if (!document.isPublic) {
if (
document.ownerId !== ctx.websocket?.me?.id &&
!document.collaborators.some(
(c) => c.userId === ctx.websocket?.me?.id && c.writable,
)
!document.collaborators.some((c) => c.userId === ctx.websocket?.me?.id && c.writable)
)
throw new Error('User is not owner or collaborator of document')
}
return pubSub.asyncIterator([
`${DocumentEvent.CHANGED}.${documentId}`,
`${DocumentEvent.CREATED}.${documentId}`,
`${DocumentEvent.DELETED}.${documentId}`,
`${DocumentEvent.SAVED}.${documentId}`,
`${DocumentEvent.PAGE_CREATED}.${documentId}`,
`${DocumentEvent.PAGE_DELETED}.${documentId}`,
`${DocumentEvent.ACTIVE_DOCUMENT_ID_CHANGED}.${documentId}`,
]) as unknown as AsyncIterable<DocumentDelta>
},