103 lines
2.1 KiB
JavaScript
103 lines
2.1 KiB
JavaScript
import ControllerModal from '../../models/product/controller'
|
|
|
|
const controller = new ControllerModal()
|
|
|
|
export const create = async (ctx, next) => {
|
|
const data = ctx.request.body
|
|
const result = await controller.create(data)
|
|
ctx.body = result
|
|
|
|
next()
|
|
}
|
|
|
|
export const update = async (ctx, next) => {
|
|
const data = ctx.request.body
|
|
const id = ctx.params.id
|
|
const result = await controller.update(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 controller.updateByAttr(data, attr, value)
|
|
ctx.body = result
|
|
|
|
next()
|
|
}
|
|
|
|
export const clearDeleted = async (ctx, next) => {
|
|
const result = await controller.clearDeleted()
|
|
ctx.body = result
|
|
|
|
next()
|
|
}
|
|
|
|
export const getByName = async (ctx, next) => {
|
|
const name = ctx.params.name
|
|
const result = await controller.getByName(name)
|
|
ctx.body = result
|
|
|
|
next()
|
|
}
|
|
|
|
export const getByMac = async (ctx, next) => {
|
|
const mac = ctx.params.mac
|
|
const result = await controller.getByMac(mac)
|
|
ctx.body = result
|
|
|
|
next()
|
|
}
|
|
|
|
export const getByMqttId = async (ctx, next) => {
|
|
const mqttId = ctx.params.mqtt_id
|
|
const result = await controller.getByMqttId(mqttId)
|
|
ctx.body = result
|
|
|
|
next()
|
|
}
|
|
|
|
export const getByAttr = async (ctx, next) => {
|
|
const attr = ctx.params.attr
|
|
const value = ctx.params.value
|
|
const result = await controller.getByAttr(attr, value)
|
|
ctx.body = result
|
|
|
|
next()
|
|
}
|
|
|
|
export const getAll = async (ctx, next) => {
|
|
const result = await controller.getAll()
|
|
ctx.body = result
|
|
|
|
next()
|
|
}
|
|
|
|
// export const createTest = async (ctx, next) => {
|
|
// const data = {
|
|
// name: 'test',
|
|
// parent: -1,
|
|
// size: 0
|
|
// }
|
|
// const result = await controller.create(data)
|
|
// ctx.body = result
|
|
|
|
// next()
|
|
// }
|
|
|
|
// export const updateTest = async (ctx, next) => {
|
|
// const data = {
|
|
// name: 'test121',
|
|
// parent: -1232,
|
|
// size: 1243
|
|
// }
|
|
// const id = 2
|
|
// const result = await controller.update(data, id)
|
|
// ctx.body = result
|
|
|
|
// next()
|
|
// }
|