UNPKG

@wepublish/api

Version:
63 lines 2.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SettingsService = void 0; const tslib_1 = require("tslib"); const common_1 = require("@nestjs/common"); const client_1 = require("@prisma/client"); const settings_utils_1 = require("./settings-utils"); let SettingsService = exports.SettingsService = class SettingsService { constructor(prisma) { this.prisma = prisma; } settingsList(filter) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const data = yield this.prisma.setting.findMany({ where: Object.assign({}, filter), orderBy: { createdAt: 'desc' } }); return data; }); } setting(id) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const data = yield this.prisma.setting.findUnique({ where: { id } }); if (!data) { throw Error(`Setting with id ${id} not found`); } return data; }); } updateSetting(input) { return tslib_1.__awaiter(this, void 0, void 0, function* () { const { name, value } = input; const fullSetting = yield this.prisma.setting.findUnique({ where: { name } }); if (!fullSetting) { throw new common_1.NotFoundException('setting', name); } const currentVal = fullSetting.value; const restriction = fullSetting.settingRestriction; (0, settings_utils_1.checkSettingRestrictions)(value, currentVal, restriction); return this.prisma.setting.update({ where: { name }, data: { value: value } }); }); } }; exports.SettingsService = SettingsService = tslib_1.__decorate([ (0, common_1.Injectable)(), tslib_1.__metadata("design:paramtypes", [client_1.PrismaClient]) ], SettingsService); //# sourceMappingURL=settings.service.js.map