Skip to content

Commit

Permalink
Check for users to be updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Nithriel committed Nov 22, 2023
1 parent 38dfbec commit e5619c7
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions migrations/20231121203719-DEVSU-2129-datafix-unreviewed-access.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,30 @@ module.exports = {
},
);

let bulkInsertList = [];

for (const element of userUpdateList) {
bulkInsertList.push(
`(${element.id},\
${unreviewedAcessGroup.id},\
'${new Date().toLocaleString()}',\
'${new Date().toLocaleString()}')`,
);
}
if (userUpdateList.length > 0) {
let bulkInsertList = [];

bulkInsertList = bulkInsertList.join(', ');
for (const element of userUpdateList) {
bulkInsertList.push(
`(${element.id},\
${unreviewedAcessGroup.id},\
'${new Date().toLocaleString()}',\
'${new Date().toLocaleString()}')`,
);
}

const insertReturn = await queryInterface.sequelize.query(
// eslint-disable-next-line no-multi-str
`INSERT INTO user_group_members (user_id, group_id, created_at, updated_at)\
VALUES ${bulkInsertList};`,
);
bulkInsertList = bulkInsertList.join(', ');

console.log(`${insertReturn[1]} users updated`);
const insertReturn = await queryInterface.sequelize.query(
// eslint-disable-next-line no-multi-str
`INSERT INTO user_group_members (user_id, group_id, created_at, updated_at)\
VALUES ${bulkInsertList};`,
);

console.log(`${insertReturn[1]} users updated`);
} else {
console.log('No users to be updated');
}
});
},

Expand Down

0 comments on commit e5619c7

Please sign in to comment.