|
|
@@ -1,5 +1,4 @@
|
|
|
import { type IGrantedGroup, GroupType } from '@growi/core';
|
|
|
-import createError from 'http-errors';
|
|
|
import { type Model, type Document, Schema } from 'mongoose';
|
|
|
|
|
|
import { getOrCreateModel } from '~/server/util/mongoose-utils';
|
|
|
@@ -8,9 +7,7 @@ import { type AiAssistant, AiAssistantShareScope, AiAssistantAccessScope } from
|
|
|
|
|
|
export interface AiAssistantDocument extends AiAssistant, Document {}
|
|
|
|
|
|
-interface AiAssistantModel extends Model<AiAssistantDocument> {
|
|
|
- setDefault(id: string, isDefault: boolean): Promise<AiAssistantDocument>;
|
|
|
-}
|
|
|
+type AiAssistantModel = Model<AiAssistantDocument>;
|
|
|
|
|
|
/*
|
|
|
* Schema Definition
|
|
|
@@ -111,19 +108,4 @@ const schema = new Schema<AiAssistantDocument>(
|
|
|
);
|
|
|
|
|
|
|
|
|
-schema.statics.setDefault = async function(id: string, isDefault: boolean): Promise<AiAssistantDocument> {
|
|
|
- const aiAssistant = await this.findOne({ _id: id, shareScope: AiAssistantAccessScope.PUBLIC_ONLY });
|
|
|
- if (aiAssistant == null) {
|
|
|
- throw createError(404, 'AiAssistant document does not exist');
|
|
|
- }
|
|
|
-
|
|
|
- await this.updateMany({ isDefault: true }, { isDefault: false });
|
|
|
-
|
|
|
- aiAssistant.isDefault = isDefault;
|
|
|
- const updatedAiAssistant = await aiAssistant.save();
|
|
|
-
|
|
|
- return updatedAiAssistant;
|
|
|
-};
|
|
|
-
|
|
|
-
|
|
|
export default getOrCreateModel<AiAssistantDocument, AiAssistantModel>('AiAssistant', schema);
|