fix: save chat

This commit is contained in:
archer 2023-05-30 00:40:03 +08:00
parent cdee91bec1
commit 59ddf09b94
No known key found for this signature in database
GPG Key ID: 166CA6BF2383B2BB

View File

@ -51,7 +51,7 @@ export async function saveChat({
userId userId
}: Props & { userId: string }) { }: Props & { userId: string }) {
await connectToDatabase(); await connectToDatabase();
await authModel({ modelId, userId, authOwner: false }); const { model } = await authModel({ modelId, userId, authOwner: false });
const content = prompts.map((item) => ({ const content = prompts.map((item) => ({
_id: item._id ? new mongoose.Types.ObjectId(item._id) : undefined, _id: item._id ? new mongoose.Types.ObjectId(item._id) : undefined,
@ -89,9 +89,14 @@ export async function saveChat({
latestChat: content[1].value latestChat: content[1].value
}).then((res) => res._id) }).then((res) => res._id)
]), ]),
// update model
...(String(model.userId) === userId
? [
Model.findByIdAndUpdate(modelId, { Model.findByIdAndUpdate(modelId, {
updateTime: new Date() updateTime: new Date()
}) // update model })
]
: [])
]); ]);
return { return {