refactor(create-config): move unique violation error handling to error-handler

This commit is contained in:
Ali BARIN
2024-08-27 16:30:05 +00:00
parent 48b2b006c0
commit 0800642a2a
5 changed files with 55 additions and 30 deletions

View File

@@ -1,19 +1,10 @@
import { renderError, renderObject } from '../../../../../helpers/renderer.js';
import { renderObject } from '../../../../../helpers/renderer.js';
import AppConfig from '../../../../../models/app-config.js';
export default async (request, response) => {
const appKey = request.params.appKey;
const appConfig = await AppConfig.query()
.findOne({ key: appKey });
if (appConfig) {
return renderError(response, [{ general: ['App config already exists.'] }], 409);
}
const createdAppConfig = await AppConfig
.query()
.insertAndFetch(appConfigParams(request));
const createdAppConfig = await AppConfig.query().insertAndFetch(
appConfigParams(request)
);
renderObject(response, createdAppConfig, { status: 201 });
};