WMS_MAIN/database/migrations/20260826100000-add-stockout-listLogs-permission.js

57 lines
1.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
/**
* 为 storage.stockout.listLogs 添加 API 权限并授权。
*
* 权限 ID(固定):565 — storage.stockout.listLogs 出库单操作日志查询
* 授权角色:经理(8)、仓库组-主管(26)、客服组-主管(28)、生产组-主管(29)、客服组-员工(30)
*/
module.exports = {
up: async queryInterface => {
await queryInterface.sequelize.query(`
INSERT INTO wms_permission (id, path, component, name, redirect, meta_title, meta_icon, hidden, always_show, parent_id, type, sort, status, created_at, update_at)
VALUES (565, 'storage.stockout.listLogs', NULL, 'storage.stockout.listLogs', NULL, 'API:出库单操作日志', NULL, 0, 0, NULL, 'api', 0, 1, NOW(), NOW())
ON DUPLICATE KEY UPDATE path='storage.stockout.listLogs', meta_title='API:出库单操作日志', type='api'
`);
const roleIds = [ 8, 26, 28, 29, 30 ];
for (const roleId of roleIds) {
await queryInterface.sequelize.query(`
UPDATE wms_role
SET permissions = JSON_ARRAY_APPEND(permissions, '$', CAST(565 AS UNSIGNED)),
updated_at = NOW()
WHERE id = ${roleId}
AND permissions IS NOT NULL
AND permissions != '*'
AND permissions != '[]'
AND JSON_VALID(permissions) = 1
AND JSON_CONTAINS(permissions, '565', '$') = 0
`);
}
},
down: async queryInterface => {
const roleIds = [ 8, 26, 28, 29, 30 ];
for (const roleId of roleIds) {
await queryInterface.sequelize.query(`
UPDATE wms_role
SET permissions = JSON_REMOVE(
permissions,
JSON_UNQUOTE(JSON_SEARCH(permissions, 'one', '565'))
),
updated_at = NOW()
WHERE id = ${roleId}
AND permissions IS NOT NULL
AND permissions != '*'
AND permissions != '[]'
`);
}
await queryInterface.sequelize.query(`
DELETE FROM wms_permission WHERE id = 565
`);
},
};