巴林闲侠
3 years ago
7 changed files with 1351 additions and 3 deletions
@ -0,0 +1,77 @@ |
|||
'use strict'; |
|||
|
|||
async function publicityGet (ctx) { |
|||
try { |
|||
const models = ctx.fs.dc.models; |
|||
const { enable } = ctx.query; |
|||
let findOption = { |
|||
where: {}, |
|||
order: [['id', 'DESC']] |
|||
} |
|||
if (enable) { |
|||
findOption.where.enable = true |
|||
} |
|||
|
|||
const roadRes = await models.Publicity.findAll(findOption) |
|||
|
|||
ctx.status = 200; |
|||
ctx.body = roadRes |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|||
ctx.status = 400; |
|||
ctx.body = { |
|||
message: typeof error == 'string' ? error : undefined |
|||
} |
|||
} |
|||
} |
|||
|
|||
async function publicityEdit (ctx) { |
|||
try { |
|||
const models = ctx.fs.dc.models; |
|||
const data = ctx.request.body; |
|||
|
|||
if (!data.publicityId) { |
|||
await models.Publicity.create(data) |
|||
} else { |
|||
await models.Publicity.update( |
|||
data, { |
|||
where: { |
|||
id: data.publicityId |
|||
} |
|||
}) |
|||
} |
|||
|
|||
ctx.status = 204 |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|||
ctx.status = 400; |
|||
ctx.body = { |
|||
message: typeof error == 'string' ? error : undefined |
|||
} |
|||
} |
|||
} |
|||
|
|||
async function publicityDel (ctx) { |
|||
try { |
|||
const models = ctx.fs.dc.models; |
|||
const { publicityId } = ctx.params; |
|||
|
|||
await models.Publicity.destroy({ |
|||
where: { |
|||
id: publicityId |
|||
} |
|||
}) |
|||
|
|||
ctx.status = 204 |
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|||
ctx.status = 400; |
|||
ctx.body = { |
|||
message: typeof error == 'string' ? error : undefined |
|||
} |
|||
} |
|||
} |
|||
|
|||
module.exports = { |
|||
publicityGet, publicityEdit, publicityDel, |
|||
}; |
@ -0,0 +1,52 @@ |
|||
/* eslint-disable*/ |
|||
'use strict'; |
|||
|
|||
module.exports = dc => { |
|||
const DataTypes = dc.ORM; |
|||
const sequelize = dc.orm; |
|||
const Publicity = sequelize.define("publicity", { |
|||
id: { |
|||
type: DataTypes.INTEGER, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: true, |
|||
field: "id", |
|||
autoIncrement: true, |
|||
unique: "publicity_id_uindex" |
|||
}, |
|||
name: { |
|||
type: DataTypes.STRING, |
|||
allowNull: false, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "name", |
|||
autoIncrement: false |
|||
}, |
|||
video: { |
|||
type: DataTypes.ARRAY(DataTypes.INTEGER), |
|||
allowNull: true, |
|||
defaultValue: null, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "video", |
|||
autoIncrement: false |
|||
}, |
|||
enable: { |
|||
type: DataTypes.BOOLEAN, |
|||
allowNull: false, |
|||
defaultValue: true, |
|||
comment: null, |
|||
primaryKey: false, |
|||
field: "enable", |
|||
autoIncrement: false |
|||
} |
|||
}, { |
|||
tableName: "publicity", |
|||
comment: "", |
|||
indexes: [] |
|||
}); |
|||
dc.models.Publicity = Publicity; |
|||
return Publicity; |
|||
}; |
File diff suppressed because it is too large
Loading…
Reference in new issue