明树Git Lab

Commit dd09080d authored by zfp1's avatar zfp1

update

parent e71b822f
Pipeline #107749 passed with stage
in 4 seconds
...@@ -71,7 +71,7 @@ async function getUserMessages(req, res, next) { ...@@ -71,7 +71,7 @@ async function getUserMessages(req, res, next) {
let limit = req.body.pagesize || req.body.pageSize || 10; let limit = req.body.pagesize || req.body.pageSize || 10;
let offset = (page - 1) * limit; let offset = (page - 1) * limit;
const messages = await DB.Message.findAll({ const ret = await DB.Message.findAndCountAll({
where: { where: {
[Op.and]: [sequelize.where( [Op.and]: [sequelize.where(
sequelize.fn('JSON_CONTAINS', sequelize.fn('JSON_CONTAINS',
...@@ -84,18 +84,19 @@ async function getUserMessages(req, res, next) { ...@@ -84,18 +84,19 @@ async function getUserMessages(req, res, next) {
{ del: 0 }, { del: 0 },
] ]
}, },
// include: [ include: [
// { {
// model: DB.User, model: DB.User,
// as: 'creatorInfo', as: 'creatorInfo',
// attributes: ['id', 'name', 'avatar'] attributes: ['id', 'name', 'avatar']
// } }
// ], ],
limit, limit,
offset, offset,
raw: true, // raw: true,
order: [['createdAt', 'DESC']], order: [['createdAt', 'DESC']],
}); });
let messages = ret.rows || [];
let newRet = []; let newRet = [];
for (let index = 0; index < messages.length; index++) { for (let index = 0; index < messages.length; index++) {
const element = messages[index]; const element = messages[index];
...@@ -106,7 +107,8 @@ async function getUserMessages(req, res, next) { ...@@ -106,7 +107,8 @@ async function getUserMessages(req, res, next) {
} }
newRet.push(element); newRet.push(element);
} }
return res.sendData(newRet); ret.rows = newRet;
return res.sendData(ret);
} }
catch (error) { catch (error) {
next(error) next(error)
......
...@@ -36,7 +36,7 @@ async function login(req, res, next) { ...@@ -36,7 +36,7 @@ async function login(req, res, next) {
model: DB.Role, model: DB.Role,
as: 'roles', as: 'roles',
// where: { del: 0 }, // where: { del: 0 },
attributes: ["id", "name"], attributes: ["id", "name", "key"],
through: { attributes: [] }, through: { attributes: [] },
include: [{ include: [{
model: DB.Menu, model: DB.Menu,
......
...@@ -252,6 +252,10 @@ Position.belongsToMany(User, { ...@@ -252,6 +252,10 @@ Position.belongsToMany(User, {
User.hasMany(Project, { foreignKey: 'projectCreator', as: 'createdProjects' }); User.hasMany(Project, { foreignKey: 'projectCreator', as: 'createdProjects' });
Project.belongsTo(User, { foreignKey: 'projectCreator', as: 'creator' }); Project.belongsTo(User, { foreignKey: 'projectCreator', as: 'creator' });
/**用户创建者-消息 1:n */
User.hasMany(Message, { foreignKey: 'creator', as: 'createMessages' });
Message.belongsTo(User, { foreignKey: 'creator', as: 'creatorInfo' });
/**项目-资源信息 1:n */ /**项目-资源信息 1:n */
Resources.hasMany(ResourcesInfo, { foreignKey: 'resourceId', as: 'resourcesInfos' }); Resources.hasMany(ResourcesInfo, { foreignKey: 'resourceId', as: 'resourcesInfos' });
ResourcesInfo.belongsTo(Resources, { foreignKey: 'resourceId' }); ResourcesInfo.belongsTo(Resources, { foreignKey: 'resourceId' });
......
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