mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-20 08:33:11 +00:00
feat: add backend
This commit is contained in:
46
src/routes/BulkAddRoute.ts
Normal file
46
src/routes/BulkAddRoute.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (C) 2019 StApps
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import { SCBulkAddRequest, SCBulkAddResponse, SCBulkAddRoute, SCNotFoundErrorResponse } from '@openstapps/core';
|
||||
import { logger } from '../common';
|
||||
import { BulkStorage } from '../storage/BulkStorage';
|
||||
import { createRoute } from './Route';
|
||||
|
||||
const bulkRouteModel = new SCBulkAddRoute();
|
||||
|
||||
/**
|
||||
* Implementation of the bulk add route (SCBulkAddRoute)
|
||||
*/
|
||||
export const bulkAddRouter = createRoute<SCBulkAddResponse>(
|
||||
bulkRouteModel,
|
||||
async (request: SCBulkAddRequest, app, params) => {
|
||||
|
||||
if (!params || typeof params.UID !== 'string') {
|
||||
throw new Error('UID of Bulk was not given, but route with obligatory parameter was called');
|
||||
}
|
||||
|
||||
const bulkMemory: BulkStorage = app.get('bulk');
|
||||
const bulk = await bulkMemory.read(params.UID);
|
||||
|
||||
if (typeof bulk === 'undefined') {
|
||||
logger.warn(`Bulk with ${params.UID} not found.`);
|
||||
throw new SCNotFoundErrorResponse(app.get('isProductiveEnvironment'));
|
||||
}
|
||||
|
||||
await bulkMemory.database.post(request, bulk);
|
||||
|
||||
return {};
|
||||
},
|
||||
);
|
||||
Reference in New Issue
Block a user