不可多得的干货,基于Vue+Nodejs实现宿舍管理系统,前端开发要会什么

{

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

  • 22
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值