2025-05-30 22:18:13 -04:00
|
|
|
import type * as t from '~/types';
|
2025-06-04 23:11:34 -04:00
|
|
|
import mongoMeili from '~/models/plugins/mongoMeili';
|
|
|
|
|
import messageSchema from '~/schema/message';
|
2025-05-30 22:18:13 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates or returns the Message model using the provided mongoose instance and schema
|
|
|
|
|
*/
|
|
|
|
|
export function createMessageModel(mongoose: typeof import('mongoose')) {
|
2025-06-04 23:11:34 -04:00
|
|
|
if (process.env.MEILI_HOST && process.env.MEILI_MASTER_KEY) {
|
|
|
|
|
messageSchema.plugin(mongoMeili, {
|
|
|
|
|
mongoose,
|
|
|
|
|
host: process.env.MEILI_HOST,
|
|
|
|
|
apiKey: process.env.MEILI_MASTER_KEY,
|
|
|
|
|
indexName: 'messages',
|
|
|
|
|
primaryKey: 'messageId',
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-30 22:18:13 -04:00
|
|
|
return mongoose.models.Message || mongoose.model<t.IMessage>('Message', messageSchema);
|
|
|
|
|
}
|