Skip to content

Commit

Permalink
Update route added (#74)
Browse files Browse the repository at this point in the history
* update route added

* update route added
  • Loading branch information
tanay13 authored Aug 12, 2020
1 parent 8ca184c commit 9a7451c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/modules/organization/controllers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Request, Response } from 'express'
import logger from '../logger/winston'
import models from './models'
import { model } from 'mongoose'

/**
* @class
Expand Down Expand Up @@ -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 */
Expand Down
19 changes: 19 additions & 0 deletions src/modules/organization/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,25 @@ class UserModel {
})

}
static async updateOrg(organization:organizationDatatype,req:Request): Promise<returnDataType>{
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
})
})
})

}



Expand Down
5 changes: 4 additions & 1 deletion src/modules/organization/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 9a7451c

Please sign in to comment.