This commit is contained in:
archer
2023-07-04 15:39:57 +08:00
parent 9bdd5f522d
commit 6e1ef89d65
44 changed files with 213 additions and 1216 deletions

View File

@@ -1,6 +1,6 @@
import type { NextApiRequest, NextApiResponse } from 'next';
import { jsonRes } from '@/service/response';
import { connectToDatabase, Chat, Model } from '@/service/mongo';
import { connectToDatabase, Chat, App } from '@/service/mongo';
import type { InitChatResponse } from '@/api/response/chat';
import { authUser } from '@/service/utils/auth';
import { ChatItemType } from '@/types/chat';
@@ -23,13 +23,13 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
// 没有 modelId 时直接获取用户的第一个id
const app = await (async () => {
if (!modelId) {
const myModel = await Model.findOne({ userId });
const myModel = await App.findOne({ userId });
if (!myModel) {
const { _id } = await Model.create({
const { _id } = await App.create({
name: '应用1',
userId
});
return (await Model.findById(_id)) as AppSchema;
return (await App.findById(_id)) as AppSchema;
} else {
return myModel;
}

View File

@@ -1,7 +1,7 @@
import type { NextApiRequest, NextApiResponse } from 'next';
import { jsonRes } from '@/service/response';
import { ChatItemType } from '@/types/chat';
import { connectToDatabase, Chat, Model } from '@/service/mongo';
import { connectToDatabase, Chat, App } from '@/service/mongo';
import { authApp } from '@/service/utils/auth';
import { authUser } from '@/service/utils/auth';
import { Types } from 'mongoose';
@@ -60,7 +60,7 @@ export async function saveChat({
}));
if (String(app.userId) === userId) {
await Model.findByIdAndUpdate(modelId, {
await App.findByIdAndUpdate(modelId, {
updateTime: new Date()
});
}
@@ -96,7 +96,7 @@ export async function saveChat({
// update app
...(String(app.userId) === userId
? [
Model.findByIdAndUpdate(modelId, {
App.findByIdAndUpdate(modelId, {
updateTime: new Date()
})
]

View File

@@ -2,7 +2,7 @@ import type { NextApiRequest, NextApiResponse } from 'next';
import { jsonRes } from '@/service/response';
import { connectToDatabase, ShareChat } from '@/service/mongo';
import { authApp, authUser } from '@/service/utils/auth';
import type { ShareChatEditType } from '@/types/model';
import type { ShareChatEditType } from '@/types/app';
/* create a shareChat */
export default async function handler(req: NextApiRequest, res: NextApiResponse) {