feat: add add new config strategy to frontend

This commit is contained in:
Elias Schneider
2022-11-28 17:50:36 +01:00
parent 1b5e53ff7e
commit 493705e4ef
20 changed files with 183 additions and 102 deletions

View File

@@ -1,4 +1,9 @@
import { Inject, Injectable } from "@nestjs/common";
import {
BadRequestException,
Inject,
Injectable,
NotFoundException,
} from "@nestjs/common";
import { Config } from "@prisma/client";
import { PrismaService } from "src/prisma/prisma.service";
@@ -38,4 +43,23 @@ export class ConfigService {
return configVariable;
});
}
async update(key: string, value: string | number | boolean) {
const configVariable = await this.prisma.config.findUnique({
where: { key },
});
if (!configVariable || configVariable.locked)
throw new NotFoundException("Config variable not found");
if (typeof value != configVariable.type)
throw new BadRequestException(
`Config variable must be of type ${configVariable.type}`
);
return await this.prisma.config.update({
where: { key },
data: { value: value.toString() },
});
}
}