import mongoose from 'mongoose' import paginate from 'mongoose-paginate-v2' const Schema = mongoose.Schema const Feedback = new Schema({ answer: { type: String }, botId: { type: String }, buttons: { type: Array }, content: { type: String }, conversionId: { type: String }, fileUrl: { type: String }, goods: { type: Array }, like: { type: Boolean }, mediaType: { type: String }, msgId: { type: String }, position: { type: String }, question: { type: String }, quoteId: { type: String }, text: { type: String }, timestamp: { type: Number }, title: { type: String }, type: { type: String }, unlike: { type: Boolean }, unlikeReason: { type: String }, }) Feedback.index({ botId: 1, conversionId: 1 }) Feedback.index({ botId: 1 }) Feedback.plugin(paginate) Feedback.statics['getFeedbackList'] = async function ({ botId, page, limit }) { const query = { botId } const options = { limit, page, select: '-botId', sort: { timestamp: -1 }, // Sorting by timestamp in descending order } // @ts-ignore const res = await this.paginate(query, options) return { list: res.docs, page: res.page, total: res.totalDocs, totalPage: res.totalPages, } } const model = mongoose.model('Feedback', Feedback) export default model