From 143a76afa69ddca19da75be36502843009a62d1d Mon Sep 17 00:00:00 2001 From: Eesh Naugraiya <106444720+EeshNaugraiya@users.noreply.github.com> Date: Mon, 12 Jun 2023 00:12:16 +0530 Subject: [PATCH 1/2] Add batch creation API --- batches.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 batches.js diff --git a/batches.js b/batches.js new file mode 100644 index 0000000..97de654 --- /dev/null +++ b/batches.js @@ -0,0 +1,39 @@ +const express = require('express'); +const { v4: uuidv4 } = require('uuid'); +const app = express(); + +// Define a global array to store the created batches +let batches = []; + +// Middleware to parse JSON request bodies +app.use(express.json()); + +// POST /batches endpoint to create a new batch +app.post('/batches', (req, res) => { + const { template, data, engineType, templateType, outputType } = req.body; + + // Generate a unique ID for the batch + const batchId = uuidv4(); + + // Create a new batch object + const newBatch = { + id: batchId, + template, + data, + engineType, + templateType, + outputType, + status: 'submitted', + }; + + // Add the new batch to the batches array + batches.push(newBatch); + + // Return the created batch in the response + res.status(201).json(newBatch); +}); + +// Start the server +app.listen(3000, () => { + console.log('Server is running on port 3000'); +}); From 92acf6be47b0ae11d0675693f531b5450e4848dc Mon Sep 17 00:00:00 2001 From: Eesh Naugraiya <106444720+EeshNaugraiya@users.noreply.github.com> Date: Tue, 20 Jun 2023 00:07:05 +0530 Subject: [PATCH 2/2] use nest.js for these files to add batch creation api --- appmodule.ts | 11 +++++++++++ batchcontroller.ts | 13 +++++++++++++ batchservice.ts | 19 +++++++++++++++++++ createbatchDTO.ts | 8 ++++++++ templaterservice.ts | 14 ++++++++++++++ 5 files changed, 65 insertions(+) create mode 100644 appmodule.ts create mode 100644 batchcontroller.ts create mode 100644 batchservice.ts create mode 100644 createbatchDTO.ts create mode 100644 templaterservice.ts diff --git a/appmodule.ts b/appmodule.ts new file mode 100644 index 0000000..e336b14 --- /dev/null +++ b/appmodule.ts @@ -0,0 +1,11 @@ +import { Module } from '@nestjs/common'; +import { BatchController } from './batch.controller'; +import { BatchService } from './batch.service'; +import { TemplaterService } from './templater.service'; + +@Module({ + imports: [], + controllers: [BatchController], + providers: [BatchService, TemplaterService], +}) +export class AppModule {} diff --git a/batchcontroller.ts b/batchcontroller.ts new file mode 100644 index 0000000..d8083ac --- /dev/null +++ b/batchcontroller.ts @@ -0,0 +1,13 @@ +import { Controller, Post, Body } from '@nestjs/common'; +import { BatchService } from './batch.service'; +import { CreateBatchDto } from './dto/create-batch.dto'; + +@Controller('batches') +export class BatchController { + constructor(private readonly batchService: BatchService) {} + + @Post() + async createBatch(@Body() createBatchDto: CreateBatchDto) { + return this.batchService.createBatch(createBatchDto); + } +} diff --git a/batchservice.ts b/batchservice.ts new file mode 100644 index 0000000..379ddac --- /dev/null +++ b/batchservice.ts @@ -0,0 +1,19 @@ +import { Injectable } from '@nestjs/common'; +import { TemplaterService } from './templater.service'; +import { CreateBatchDto } from './dto/create-batch.dto'; + +@Injectable() +export class BatchService { + constructor(private readonly templaterService: TemplaterService) {} + + async createBatch(createBatchDto: CreateBatchDto) { + // Perform any necessary validation or pre-processing here + + // Call the Templater service to create the batch + const batch = await this.templaterService.createBatch(createBatchDto); + + // Perform any additional operations or post-processing if needed + + return batch; + } +} diff --git a/createbatchDTO.ts b/createbatchDTO.ts new file mode 100644 index 0000000..d152a41 --- /dev/null +++ b/createbatchDTO.ts @@ -0,0 +1,8 @@ +export class CreateBatchDto { + template: any; // Replace with appropriate type + data: any; // Replace with appropriate type + engineType: string; + templateType: string; + outputType: string; + } + \ No newline at end of file diff --git a/templaterservice.ts b/templaterservice.ts new file mode 100644 index 0000000..7a38c68 --- /dev/null +++ b/templaterservice.ts @@ -0,0 +1,14 @@ +import { Injectable } from '@nestjs/common'; +import axios from 'axios'; +import { CreateBatchDto } from './dto/create-batch.dto'; + +@Injectable() +export class TemplaterService { + async createBatch(createBatchDto: CreateBatchDto) { + // Make API call to Templater to create a new batch + const response = await axios.post('/templater/batches', createBatchDto); + + // Return the created batch from the response + return response.data; + } +}