"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SeedSetting1623381200659 = void 0;
const setting_base_1 = require("@things-factory/setting-base");
const shell_1 = require("@things-factory/shell");
const typeorm_1 = require("typeorm");
class SeedSetting1623381200659 {
    async up(queryRunner) {
        await (0, typeorm_1.getConnection)().transaction(async (trx) => {
            const domains = await trx.getRepository(shell_1.Domain).find({ where: { extType: 'warehouse' } });
            await Promise.all(domains.map(async (domain) => {
                await trx.getRepository(setting_base_1.Setting).save({
                    domain,
                    name: 'rule-for-storing-product',
                    description: 'location sorting rules',
                    category: 'location',
                    value: '{"name":"DESC"}'
                });
            }));
        });
    }
    async down(queryRunner) {
        await (0, typeorm_1.getConnection)().transaction(async (trx) => {
            const settings = await trx.getRepository(setting_base_1.Setting).find({ where: { name: 'rule-for-storing-product' } });
            if (settings.length >= 0) {
                const settingIds = settings.map((setting) => setting.id);
                await trx.getRepository(setting_base_1.Setting).delete(settingIds);
            }
        });
    }
}
exports.SeedSetting1623381200659 = SeedSetting1623381200659;
//# sourceMappingURL=1623381200659-SeedStoringRule.js.map