mirror of
https://github.com/cheveguerra/whaticket-community.git
synced 2026-04-18 19:59:20 +00:00
migrated setting routes to typescript
This commit is contained in:
26
backend/src/services/SettingServices/UpdateSettingService.ts
Normal file
26
backend/src/services/SettingServices/UpdateSettingService.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import AppError from "../../errors/AppError";
|
||||
import Setting from "../../models/Setting";
|
||||
|
||||
interface Request {
|
||||
key: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
const UpdateSettingService = async ({
|
||||
key,
|
||||
value
|
||||
}: Request): Promise<Setting | undefined> => {
|
||||
const setting = await Setting.findOne({
|
||||
where: { key }
|
||||
});
|
||||
|
||||
if (!setting) {
|
||||
throw new AppError("No setting found with this ID.", 404);
|
||||
}
|
||||
|
||||
await setting.update({ value });
|
||||
|
||||
return setting;
|
||||
};
|
||||
|
||||
export default UpdateSettingService;
|
||||
Reference in New Issue
Block a user