update something can update

This commit is contained in:
2024-11-08 17:27:09 +07:00
parent 7eabba1868
commit d7c7f8a782
10 changed files with 93 additions and 19 deletions

View File

@@ -1,4 +1,4 @@
import { Inject, Injectable } from '@nestjs/common'
import { Inject, Injectable, Logger } from '@nestjs/common'
import {
Pothos,
PothosRef,
@@ -148,6 +148,8 @@ export class MessageSchema extends PothosSchema {
'sender',
'sentAt',
'context',
'recipient',
'recipientId',
]),
description: 'The message to send.',
required: true,
@@ -167,14 +169,19 @@ export class MessageSchema extends PothosSchema {
if (!args.input.sender) {
throw new Error('Cannot get sender from context')
}
// check if content is empty
if (!args.input.content || args.input.content.trim() === '') {
throw new Error('Content cannot be empty')
}
args.input.context = messageContext
// check if content is longer than 1024 characters
if (args.input.content.length > 1024) {
throw new Error('Content cannot be longer than 1024 characters')
}
const message = await this.prisma.message.create({
...query,
data: args.input,
})
if (ctx.isSubscription) {
throw new Error('Not allowed')
}
ctx.http.pubSub.publish(`MESSAGE_SENT_${message.chatRoomId}`, message)
return message
},