mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-19 08:02:55 +00:00
47 lines
1.7 KiB
TypeScript
47 lines
1.7 KiB
TypeScript
/*
|
|
* 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 {};
|
|
},
|
|
);
|