Commit ff5c7ef7 authored by 任国军's avatar 任国军

fix bugs

parent 3e8f497d
Pipeline #19401 passed with stage
in 1 minute 5 seconds
'use strict'; 'use strict';
'use strict';
const moment = require('moment'); const moment = require('moment');
module.exports = app => { module.exports = app => {
const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM, FLOAT } = app.Sequelize; const { STRING, INTEGER, DATE, DECIMAL, TEXT, ENUM, FLOAT } = app.Sequelize;
const CourseOnlineArea = app.classModel.define('courseOnlineArea', { const CourseOnlineArea = app.classModel.define('course_online_area', {
id: { id: {
type: INTEGER, type: INTEGER,
primaryKey: true, primaryKey: true,
autoIncrement: true autoIncrement: true,
}, },
institution_id: INTEGER, institution_id: INTEGER,
name: STRING, name: STRING,
address: STRING, address: STRING,
phone: STRING, phone: STRING,
lat: DECIMAL, lat: DECIMAL,
lng: DECIMAL, lng: DECIMAL,
status: ENUM('offline', 'online'), status: ENUM('offline', 'online'),
is_deleted: INTEGER, is_deleted: INTEGER,
created_time: { created_time: {
type: DATE, type: DATE,
allowNull: true, allowNull: true,
get() { get() {
const date = this.getDataValue('created_time'); const date = this.getDataValue('created_time');
return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined; return date ? moment(date).format('YYYY-MM-DD HH:mm:ss') : undefined;
}, },
} },
}, { }, {
timestamps: false, timestamps: false,
tableName: 'courseOnlineArea', tableName: 'course_online_area',
}); });
CourseOnlineArea.one = async (data) => { CourseOnlineArea.one = async data => {
const attributes = data.attributes ? data.attributes : {}; const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {}; const where = data.where ? data.where : {};
return await CourseOnlineArea.findOne({ return await CourseOnlineArea.findOne({
attributes: attributes, attributes,
where: where, where,
}); });
} };
CourseOnlineArea.all = async (data) => { CourseOnlineArea.all = async data => {
const attributes = data.attributes ? data.attributes : {}; const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {}; const where = data.where ? data.where : {};
const order = data.order ? data.order : []; const order = data.order ? data.order : [];
return await CourseOnlineArea.findAll({ return await CourseOnlineArea.findAll({
attributes: attributes, attributes,
where: where, where,
order, order,
}); });
} };
CourseOnlineArea.list = async (data = {}) => { CourseOnlineArea.list = async (data = {}) => {
const limit = data.limit ? Number(data.limit) : 10; const limit = data.limit ? Number(data.limit) : 10;
const page = data.page ? data.page : 1; const page = data.page ? data.page : 1;
const order = data.order ? data.order : []; const order = data.order ? data.order : [];
const attributes = data.attributes ? data.attributes : {}; const attributes = data.attributes ? data.attributes : {};
const where = data.where ? data.where : {}; const where = data.where ? data.where : {};
const condition = { const condition = {
offset: (page - 1) * limit, offset: (page - 1) * limit,
limit, limit,
where: where, where,
order: order, order,
attributes: attributes, attributes,
}; };
const { count, rows } = await CourseOnlineArea.findAndCountAll(condition); const { count, rows } = await CourseOnlineArea.findAndCountAll(condition);
return { page, count, rows }; return { page, count, rows };
} };
CourseOnlineArea.add = async (data) => { CourseOnlineArea.add = async data => {
try { try {
//返回promise对象实力 instance // 返回promise对象实力 instance
const res = await CourseOnlineArea.create(data); const res = await CourseOnlineArea.create(data);
//从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null // 从promise 实例中中获得需要的id号,id 必须是自增长,而且必须主键,否则返回null
return res.id; return res.id;
} catch (error) { } catch (error) {
throw (error); throw (error);
}
} }
};
CourseOnlineArea.edit = async (data) => { CourseOnlineArea.edit = async data => {
const where = data.where; const where = data.where;
const params = data.params; const params = data.params;
try { try {
const res = await CourseOnlineArea.update(params, { where: where }) const res = await CourseOnlineArea.update(params, { where });
return res; return res;
} catch (error) { } catch (error) {
throw (error); throw (error);
}
} }
};
return CourseOnlineArea; return CourseOnlineArea;
}; };
\ No newline at end of file
...@@ -56,7 +56,7 @@ class OnlineService extends Service { ...@@ -56,7 +56,7 @@ class OnlineService extends Service {
const cats = await ctx.classModel.V4.CourseOnlineCat.findAll({ where: { id: { $in: catIds } }, attributes: [ 'id', 'name' ] }); const cats = await ctx.classModel.V4.CourseOnlineCat.findAll({ where: { id: { $in: catIds } }, attributes: [ 'id', 'name' ] });
// 收藏信息 // 收藏信息
const userCollect = await ctx.classModel.V4.CourseUserCollection.findOne({ where: { user_uuid: ctx.userUuid, type: 3, type_id: id, status: 'online', is_deleted: 0 } }); const userCollect = await ctx.classModel.V4.CourseUserCollection.findOne({ where: { user_uuid: ctx.userUuid, type: 3, type_id: id, is_deleted: 0 } });
const ret = { const ret = {
id, id,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment