From e44dc9e3246ea90d22015996cf244a9cfe6e0bf8 Mon Sep 17 00:00:00 2001 From: Tanay Raj Date: Wed, 12 Aug 2020 23:32:04 +0530 Subject: [PATCH 1/2] update route added --- src/modules/organization/controllers.ts | 15 +++++++++++++++ src/modules/organization/models.ts | 19 +++++++++++++++++++ 2 files changed, 34 insertions(+) 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 + }) + }) + }) + + } From 8e769a6d6e23d1fc634107ae616075b1e95a48c7 Mon Sep 17 00:00:00 2001 From: Tanay Raj Date: Wed, 12 Aug 2020 23:38:21 +0530 Subject: [PATCH 2/2] update route added --- src/modules/organization/routes.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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