update
This commit is contained in:
parent
a244d98806
commit
b8998bb0bf
2 changed files with 22 additions and 5 deletions
|
@ -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) {
|
||||
|
|
|
@ -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: {
|
||||
|
|
Loading…
Reference in a new issue