Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update route added #74

Merged
merged 2 commits into from
Aug 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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