Files
controller-wisetopapiserver/src/models/controller/task.js
T
2021-06-28 08:58:23 +08:00

106 lines
1.7 KiB
JavaScript

const db = require('../../db/database')
// const Op = db.Sequelize.Op
class TaskModel {
async create (req) {
console.log(req)
return db.tasks.create(req)
}
async update (req) {
const ret = await db.tasks.update(
req,
{
where: {}
}
)
return ret
}
async updateByID (req, id) {
const ret = await db.tasks.update(
req,
{
where: {
id: id
}
}
)
return ret
}
async updateByAttr (req, attr, value) {
const whereObj = {}
const attrList = attr.split('-')
const valueList = value.split('-')
attrList.forEach((key, idx) => {
whereObj[key] = valueList[idx]
})
const ret = await db.tasks.update(
req,
{
where: whereObj
}
)
return ret
}
async clearDeleted () {
const ret = await db.tasks.delete(
{
where: {
deleted: true
}
}
)
return ret
}
async getByID (id) {
const ret = await db.tasks.findAll(
{
where: {
id: id
}
}
)
return ret
}
async getByName (name) {
const ret = await db.tasks.findAll(
{
where: {
name: name
}
}
)
return ret
}
async getByAttr (attr, value) {
const whereObj = {}
const attrList = attr.split('-')
const valueList = value.split('-')
attrList.forEach((key, idx) => {
whereObj[key] = valueList[idx]
})
const ret = await db.tasks.findAll(
{
where: whereObj
}
)
return ret
}
async getAll () {
const ret = await db.tasks.findAll()
return ret
}
}
export default TaskModel