{
model: Room,
where: { floorId }
}
],
limit: step,
offset: step * (current - 1),
order: [[“createdAt”, “DESC”]]
})
} else if (buildingId) {
result = await GetupRecord.findAndCountAll({
where: {
createdAt: {
}
},
include: [
{
model: Room,
where: { buildingId }
}
],
limit: step,
offset: step * (current - 1),
order: [[“createdAt”, “DESC”]]
})
} else {
result = await GetupRecord.findAndCountAll({
where: {
createdAt: {
}
},
limit: step,
offset: step * (current - 1),
order: [[“createdAt”, “DESC”]]
})
}
const getStudentInfo = require(“./user_controller”).getStudentInfo
let rows = []
for (let record of result.rows) {
record = record.toJSON()
delete record.room
const userInfo = await getStudentInfo(record.userId)
record = Object.assign(userInfo, record)
record.time = moment(record.createdAt).format(“HH:mm”)
record.date = moment(record.createdAt).format(“YYYY-MM-DD”)
if (parseInt(moment(record.createdAt).format(“HH”)) < getupEarlyPoint) {
record.early = true
} else {
record.early = false
}
rows.push(record)
}
result.rows = rows
return result
},
// back 相关
async addBackRecord(userId) {
const user = await User.findOne({ where: { id: userId } })
const todyRecord = await BackRecord.findOne({
where: {
userId: user.id,
roomId: user.roomId,
createdAt: {
.startOf(“day”)
.toDate(),
.endOf(“day”)
.toDate()
}
}
})
if (todyRecord) {
throw new Error(“当天已经有记录,记录失败!”)
}
return await BackRecord.create({ userId: user.id, roomId: user.roomId })
},
async getUserBackRecords(userId, days, pure = false) {
days = parseInt(days)
const user = await User.findOne({ where: { id: userId } })
const roomId = user.roomId
const room = await Room.findOne({ where: { id: roomId } })
// 获取最近 days 天的记录
const startTime = moment()
.subtract(days - 1 /* -1 代表查询天数包括今天 */, “days”)
.startOf(“day”)
.toDate()
const allRecords = []
for (let i = 0; i < days; i++) {
const todayStart = moment(startTime)
.add(i, “days”)
.toDate()
const todayEnd = moment(todayStart)
.endOf(“day”)
.toDate()
let record = await BackRecord.findOne({
where: {
userId,
roomId,
createdAt: {
}
},
attributes: { exclude: [“updatedAt”, “del