明树Git Lab

Commit dd09080d authored by zfp1's avatar zfp1

update

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