From 9a7451c8f1b69b150c66a5d72896798982cf91db Mon Sep 17 00:00:00 2001 From: Tanay Raj Date: Thu, 13 Aug 2020 05:13:23 +0530 Subject: [PATCH] Update route added (#74) * update route added * update route added --- src/modules/organization/controllers.ts | 15 +++++++++++++++ src/modules/organization/models.ts | 19 +++++++++++++++++++ src/modules/organization/routes.ts | 5 ++++- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/modules/organization/controllers.ts b/src/modules/organization/controllers.ts index d2c3287..88082be 100644 --- a/src/modules/organization/controllers.ts +++ b/src/modules/organization/controllers.ts @@ -1,6 +1,7 @@ import { Request, Response } from 'express' import logger from '../logger/winston' import models from './models' +import { model } from 'mongoose' /** * @class @@ -34,6 +35,20 @@ class OrganizationOperations { } } + static async update(request:Request,response:Response){ + try{ + const data = await models.updateOrg(request.body,request) + response.json(data) + } catch(err){ + response.json({ + error:err.error, + message: err.message, + + }) + } + + } + } /** Export controller to be attached to routes */ diff --git a/src/modules/organization/models.ts b/src/modules/organization/models.ts index 4eb090c..9ce35a0 100644 --- a/src/modules/organization/models.ts +++ b/src/modules/organization/models.ts @@ -79,6 +79,25 @@ class UserModel { }) } + static async updateOrg(organization:organizationDatatype,req:Request): Promise{ + return new Promise((resolve,reject)=>{ + Organization.findByIdAndUpdate(req.params.id,req.body.Organization) + .then(()=>{ + resolve({ + error: false, + message:'updated succesfully', + payload: 'Org updated' + }) + }) + .catch((err)=>{ + reject({ + error:true, + message:err + }) + }) + }) + + } diff --git a/src/modules/organization/routes.ts b/src/modules/organization/routes.ts index ff6cc80..5683b50 100644 --- a/src/modules/organization/routes.ts +++ b/src/modules/organization/routes.ts @@ -29,7 +29,10 @@ const router = express.Router() */ router.post('/register', Controller.register) +router.delete('/:id',Controller.delete) + +router.put('/:id',Controller.update) /** Export router to be included into main application */ -router.delete('/:id',Controller.delete) + export default router