Yuki Takei 1 год назад
Родитель
Сommit
0199e00927
1 измененных файлов с 1 добавлено и 4 удалено
  1. 1 4
      apps/app/src/server/util/mongoose-utils.ts

+ 1 - 4
apps/app/src/server/util/mongoose-utils.ts

@@ -27,10 +27,7 @@ export const getModelSafely = <Interface, Method = Interface>(modelName: string)
 
 // TODO: Do not use any type
 export const getOrCreateModel = <Interface, Method>(modelName: string, schema: any): Method & Model<Interface & Document> => {
-  if (mongoose.modelNames().includes(modelName)) {
-    return mongoose.model<Interface & Document, Method & Model<Interface & Document>>(modelName);
-  }
-  return mongoose.model<Interface & Document, Method & Model<Interface & Document>>(modelName, schema);
+  return getModelSafely(modelName) ?? mongoose.model<Interface & Document, Method & Model<Interface & Document>>(modelName, schema);
 };
 
 // supress deprecation warnings