From b8998bb0bfd78cbabcdacbc744ecb7f59895dfbf Mon Sep 17 00:00:00 2001 From: Matthieu Bessat Date: Sat, 11 Jul 2020 14:31:35 +0200 Subject: [PATCH] update --- .../AdminOrganizationController.ts | 25 ++++++++++++++++--- src/models/Organization.ts | 2 +- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/controllers/AdminOrganizationController.ts b/src/controllers/AdminOrganizationController.ts index 4552008..4cd58d3 100644 --- a/src/controllers/AdminOrganizationController.ts +++ b/src/controllers/AdminOrganizationController.ts @@ -5,19 +5,20 @@ import cryptoRandomString from 'crypto-random-string' export default class AdminOrganizationController { static getMany(req: express.Request, res: express.Response) { Organization.find().then(data => { - res.json(data) + res.json({ success: true, data }) }) } static getOne(req: express.Request, res: express.Response) { Organization.findById(req.params.id).then(data => { - res.json(data) + res.json({ success: true, data }) }) } static store(req: express.Request, res: express.Response) { Organization.create({ token: cryptoRandomString({ length: 10, type: 'distinguishable' }), + createdAt: new Date(), ...req.body }).then(data => { res.json({ @@ -33,7 +34,10 @@ export default class AdminOrganizationController { } static update(req: express.Request, res: express.Response) { - Organization.updateOne({ _id: req.params.id }, req.body).then(data => { + Organization.updateOne({ _id: req.params.id }, { + ...req.body, + updatedAt: new Date() + }).then(data => { res.json({ success: true, data @@ -66,7 +70,20 @@ export default class AdminOrganizationController { } static resetToken(req: express.Request, res: express.Response) { - + Organization.updateOne({ _id: req.params.id }, { + token: cryptoRandomString({ length: 10, type: 'distinguishable' }), + updatedAt: new Date() + }).then(data => { + res.json({ + success: true, + data + }) + }).catch(err => { + res.status(400).json({ + success: false, + errors: err.errors !== undefined ? err.errors : err + }) + }) } static approve(req: express.Request, res: express.Response) { diff --git a/src/models/Organization.ts b/src/models/Organization.ts index 36ae545..4f9f864 100644 --- a/src/models/Organization.ts +++ b/src/models/Organization.ts @@ -73,7 +73,7 @@ const OrganizationVersion = new Schema({ }) const Organization = new Schema({ - admin_name: { type: String, required: true }, + adminName: { type: String, required: true }, email: { type: String, required: true }, token: { type: String, required: true }, validationState: {