This commit is contained in:
Matthieu Bessat 2020-07-11 14:31:35 +02:00
parent a244d98806
commit b8998bb0bf
2 changed files with 22 additions and 5 deletions

View file

@ -5,19 +5,20 @@ import cryptoRandomString from 'crypto-random-string'
export default class AdminOrganizationController { export default class AdminOrganizationController {
static getMany(req: express.Request, res: express.Response) { static getMany(req: express.Request, res: express.Response) {
Organization.find().then(data => { Organization.find().then(data => {
res.json(data) res.json({ success: true, data })
}) })
} }
static getOne(req: express.Request, res: express.Response) { static getOne(req: express.Request, res: express.Response) {
Organization.findById(req.params.id).then(data => { Organization.findById(req.params.id).then(data => {
res.json(data) res.json({ success: true, data })
}) })
} }
static store(req: express.Request, res: express.Response) { static store(req: express.Request, res: express.Response) {
Organization.create({ Organization.create({
token: cryptoRandomString({ length: 10, type: 'distinguishable' }), token: cryptoRandomString({ length: 10, type: 'distinguishable' }),
createdAt: new Date(),
...req.body ...req.body
}).then(data => { }).then(data => {
res.json({ res.json({
@ -33,7 +34,10 @@ export default class AdminOrganizationController {
} }
static update(req: express.Request, res: express.Response) { 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({ res.json({
success: true, success: true,
data data
@ -66,7 +70,20 @@ export default class AdminOrganizationController {
} }
static resetToken(req: express.Request, res: express.Response) { 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) { static approve(req: express.Request, res: express.Response) {

View file

@ -73,7 +73,7 @@ const OrganizationVersion = new Schema({
}) })
const Organization = new Schema({ const Organization = new Schema({
admin_name: { type: String, required: true }, adminName: { type: String, required: true },
email: { type: String, required: true }, email: { type: String, required: true },
token: { type: String, required: true }, token: { type: String, required: true },
validationState: { validationState: {