refactor(create-config): move unique violation error handling to error-handler
This commit is contained in:
@@ -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 });
|
||||
};
|
||||
|
Reference in New Issue
Block a user