tmp
This commit is contained in:
@@ -142,50 +142,34 @@ const EscortRecordSchema = mongoose.Schema(
|
||||
);
|
||||
|
||||
/**
|
||||
* 根据用户ID查找陪诊记录
|
||||
*
|
||||
* @param {ObjectId} userId - 订单提交用户ID
|
||||
* 查找陪诊记录(支持多条件筛选)
|
||||
*
|
||||
* @param {Object} options - 查询选项
|
||||
* @param {number} [options.page=1] - 页码
|
||||
* @param {number} [options.pageSize=20] - 每页数量
|
||||
* @param {string} [options.status] - 状态筛选
|
||||
* @param {Array<string>} options.status - 状态筛选(必需,数组)
|
||||
* @param {ObjectId} [options.userId] - 订单提交用户ID(可选)
|
||||
* @param {string} [options.appointmentDate] - 预约日期筛选(可选,格式 YYYY-MM-DD)
|
||||
* @param {Function} [cb] - 可选的回调函数
|
||||
* @returns {Promise<Array>} 陪诊记录列表(按预约日期倒序)
|
||||
*/
|
||||
EscortRecordSchema.statics.findRecordsByUser = async function (userId, options = {}, cb) {
|
||||
const { page = 1, pageSize = 20, status } = options;
|
||||
const filter = { userId };
|
||||
EscortRecordSchema.statics.findRecords = async function (options = {}, cb) {
|
||||
const { page = 1, pageSize = 20, status, userId, appointmentDate } = options;
|
||||
const filter = {};
|
||||
|
||||
if (status) {
|
||||
filter.status = status;
|
||||
if (status && Array.isArray(status) && status.length > 0) {
|
||||
filter.status = { $in: status };
|
||||
}
|
||||
|
||||
const skip = (page - 1) * pageSize;
|
||||
if (userId) {
|
||||
filter.userId = userId;
|
||||
}
|
||||
|
||||
return await this.find(filter)
|
||||
.sort({ "schedule.date": -1 })
|
||||
.skip(skip)
|
||||
.limit(pageSize)
|
||||
.exec(cb);
|
||||
};
|
||||
|
||||
/**
|
||||
* 根据陪诊员ID查找陪诊记录
|
||||
*
|
||||
* @param {ObjectId} attendantId - 陪诊员用户ID
|
||||
* @param {Object} options - 查询选项
|
||||
* @param {number} [options.page=1] - 页码
|
||||
* @param {number} [options.pageSize=20] - 每页数量
|
||||
* @param {string} [options.status] - 状态筛选
|
||||
* @param {Function} [cb] - 可选的回调函数
|
||||
* @returns {Promise<Array>} 陪诊记录列表(按预约日期倒序)
|
||||
*/
|
||||
EscortRecordSchema.statics.findRecordsByAttendant = async function (attendantId, options = {}, cb) {
|
||||
const { page = 1, pageSize = 20, status } = options;
|
||||
const filter = { "attendant.id": attendantId };
|
||||
|
||||
if (status) {
|
||||
filter.status = status;
|
||||
if (appointmentDate) {
|
||||
const start = new Date(appointmentDate);
|
||||
const end = new Date(start);
|
||||
end.setDate(end.getDate() + 1);
|
||||
filter["schedule.date"] = { $gte: start, $lt: end };
|
||||
}
|
||||
|
||||
const skip = (page - 1) * pageSize;
|
||||
|
||||
Reference in New Issue
Block a user