diff --git a/src/controllers/RunnerCardController.ts b/src/controllers/RunnerCardController.ts
index 808b0d5..84f10eb 100644
--- a/src/controllers/RunnerCardController.ts
+++ b/src/controllers/RunnerCardController.ts
@@ -50,13 +50,22 @@ export class RunnerCardController {
@Post('/bulk')
@Authorized("CARD:CREATE")
@ResponseSchema(ResponseEmpty, { statusCode: 200 })
- @OpenAPI({ description: "Create blank cards in bulk.
Just provide the count as a query param and wait for the 200 response." })
- async postBlancoBulk(@QueryParam("count") count: number) {
+ @OpenAPI({ description: "Create blank cards in bulk.
Just provide the count as a query param and wait for the 200 response.
You can provide the 'returnCards' query param if you want to receive the RESPONSERUNNERCARD objects in the response." })
+ async postBlancoBulk(@QueryParam("count") count: number, @QueryParam("returnCards") returnCards: boolean = false) {
let createPromises = new Array();
for (let index = 0; index < count; index++) {
createPromises.push(this.cardRepository.save({ runner: null, enabled: true }))
}
- await Promise.all(createPromises);
+
+ const cards = await Promise.all(createPromises);
+
+ if (returnCards) {
+ let responseCards: ResponseRunnerCard[] = new Array();
+ cards.forEach(card => {
+ responseCards.push(new ResponseRunnerCard(card));
+ });
+ return responseCards;
+ }
let response = new ResponseEmpty();
response.response = `Created ${count} new blanco cards.`
return response;
diff --git a/src/tests/cards/cards_add.spec.ts b/src/tests/cards/cards_add.spec.ts
index 9b13baa..05d8ace 100644
--- a/src/tests/cards/cards_add.spec.ts
+++ b/src/tests/cards/cards_add.spec.ts
@@ -156,11 +156,23 @@ describe('POST /api/cards/bulk successfully', () => {
expect(res.status).toEqual(200);
expect(res.headers['content-type']).toContain("application/json");
});
+ it('creating a single new bulk card and letting the system return it should return 200', async () => {
+ const res = await axios.post(base + '/api/cards/bulk?count=1&returnCards=true', {}, axios_config);
+ expect(res.status).toEqual(200);
+ expect(res.headers['content-type']).toContain("application/json");
+ expect(res.data[0].id).toBeDefined();
+ });
it('creating 50 new bulk card should return 200', async () => {
const res = await axios.post(base + '/api/cards/bulk?count=50', {}, axios_config);
expect(res.status).toEqual(200);
expect(res.headers['content-type']).toContain("application/json");
});
+ it('creating 50 new bulk cards and letting the system return it should return 200', async () => {
+ const res = await axios.post(base + '/api/cards/bulk?count=50&returnCards=true', {}, axios_config);
+ expect(res.status).toEqual(200);
+ expect(res.headers['content-type']).toContain("application/json");
+ expect(res.data.length).toEqual(50);
+ });
it('creating 250 new bulk card should return 200', async () => {
const res = await axios.post(base + '/api/cards/bulk?count=250', {}, axios_config);
expect(res.status).toEqual(200);