[init] task model
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
import TaskModal from '../../models/controller/task'
|
||||
|
||||
const task = new TaskModal()
|
||||
|
||||
export const create = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
const result = await task.create(data)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const update = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
const result = await task.update(data)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const updateByID = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
const id = ctx.params.id
|
||||
const result = await task.updateByID(data, id)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const updateByAttr = async (ctx, next) => {
|
||||
const data = ctx.request.body
|
||||
const attr = ctx.params.attr
|
||||
const value = ctx.params.value
|
||||
const result = await task.updateByAttr(data, attr, value)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const clearDeleted = async (ctx, next) => {
|
||||
const result = await task.clearDeleted()
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getByAttr = async (ctx, next) => {
|
||||
const attr = ctx.params.attr
|
||||
const value = ctx.params.value
|
||||
const result = await task.getByAttr(attr, value)
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
|
||||
export const getAll = async (ctx, next) => {
|
||||
const result = await task.getAll()
|
||||
ctx.body = result
|
||||
|
||||
next()
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import * as auth from './auth'
|
||||
import * as controller from './product/controller'
|
||||
import * as device from './product/device'
|
||||
import * as collection from './file/collection'
|
||||
import * as task from './controller/task'
|
||||
import * as recordingDataMeta from './file/recording_data_meta'
|
||||
import * as recordingDataRaw from './file/recording_data_raw'
|
||||
import * as recordingDataMini from './file/recording_data_mini'
|
||||
@@ -15,6 +16,7 @@ export default {
|
||||
controller,
|
||||
device,
|
||||
collection,
|
||||
task,
|
||||
recordingDataMeta,
|
||||
recordingDataRaw,
|
||||
recordingDataMini
|
||||
|
||||
@@ -24,6 +24,7 @@ db.sequelize = sequelize
|
||||
|
||||
db.tutorials = require('./schema/tutirial.model')(sequelize, Sequelize)
|
||||
db.controllers = require('./schema/controller.model')(sequelize, Sequelize)
|
||||
db.tasks = require('./schema/task.model')(sequelize, Sequelize)
|
||||
db.devices = require('./schema/device.model')(sequelize, Sequelize)
|
||||
db.collections = require('./schema/collection.model')(sequelize, Sequelize)
|
||||
db.recording_data_metas = require('./schema/recording_data_meta.model')(sequelize, Sequelize)
|
||||
|
||||
@@ -28,6 +28,10 @@ module.exports = (sequelize, Sequelize) => {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
mqtt_id: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
mqtt_address: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
@@ -64,28 +68,41 @@ module.exports = (sequelize, Sequelize) => {
|
||||
scanned: []
|
||||
}
|
||||
},
|
||||
device_scanned: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {}
|
||||
},
|
||||
device_auto_join: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {}
|
||||
},
|
||||
// project/task: {
|
||||
// running: [id...],
|
||||
// library: [id...]
|
||||
// }
|
||||
project: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {
|
||||
running: [],
|
||||
library: []
|
||||
}
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
task: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {
|
||||
running: [],
|
||||
library: []
|
||||
}
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
// task: {
|
||||
// type: Sequelize.JSONB,
|
||||
// defaultValue: {
|
||||
// running: [],
|
||||
// library: []
|
||||
// }
|
||||
// },
|
||||
software_version: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
status: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
deleted: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: false
|
||||
|
||||
@@ -1,16 +1,33 @@
|
||||
module.exports = (sequelize, Sequelize) => {
|
||||
const Task = sequelize.define('task', {
|
||||
name: {
|
||||
type: Sequelize.STRING
|
||||
},
|
||||
description: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
configuration: {
|
||||
describe: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
status: {
|
||||
type: Sequelize.STRING,
|
||||
defaultValue: ''
|
||||
},
|
||||
device_config: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {}
|
||||
},
|
||||
chart_config: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {}
|
||||
},
|
||||
formula_config: {
|
||||
type: Sequelize.JSONB,
|
||||
defaultValue: {}
|
||||
},
|
||||
controller_id: {
|
||||
type: Sequelize.INTEGER,
|
||||
defaultValue: -1
|
||||
},
|
||||
deleted: {
|
||||
type: Sequelize.BOOLEAN,
|
||||
defaultValue: false
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
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
|
||||
@@ -4,12 +4,8 @@ const db = require('../../db/database')
|
||||
|
||||
class ControllerModel {
|
||||
async create (req) {
|
||||
return db.controllers.create({
|
||||
name: req.name,
|
||||
mac_address: req.mac_address,
|
||||
software_version: req.software_version,
|
||||
wifi_name: req.wifi_name
|
||||
})
|
||||
console.log(req)
|
||||
return db.controllers.create(req)
|
||||
}
|
||||
|
||||
async update (req) {
|
||||
|
||||
Reference in New Issue
Block a user