"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SeedLocationRecommendSetting1623308919899 = void 0;
const setting_base_1 = require("@things-factory/setting-base");
const shell_1 = require("@things-factory/shell");
const typeorm_1 = require("typeorm");
class SeedLocationRecommendSetting1623308919899 {
    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: 'location-recommendation-level',
                    description: 'Location recommendation level',
                    category: 'location',
                    value: 'level 1'
                });
            }));
        });
    }
    async down(queryRunner) {
        await (0, typeorm_1.getConnection)().transaction(async (trx) => {
            const settings = await trx
                .getRepository(setting_base_1.Setting)
                .find({ where: { name: 'location-recommendation-level' } });
            if (settings.length >= 0) {
                const settingIds = settings.map((setting) => setting.id);
                await trx.getRepository(setting_base_1.Setting).delete(settingIds);
            }
        });
    }
}
exports.SeedLocationRecommendSetting1623308919899 = SeedLocationRecommendSetting1623308919899;
//# sourceMappingURL=1623308919899-SeedLocationRecommendSetting.js.map