Skip to content

Commit

Permalink
Add new JSON api (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsanmasdar committed Aug 22, 2018
1 parent efc4013 commit d1440b0
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions server/routes/api/user.ts
Expand Up @@ -3,6 +3,7 @@ import * as express from "express";
import * as json2csv from "json2csv";
import * as archiver from "archiver";
import * as uuid from "uuid/v4";
import * as bodyParser from "body-parser";

import {
STORAGE_ENGINE,
Expand Down Expand Up @@ -325,6 +326,32 @@ userRoutes.route("/status").post(isAdmin, uploadHandler.any(), async (request, r
}
});

userRoutes.route("/status_api").post(isAdmin, bodyParser.json(), async (request, response): Promise<void> => {
let user = await User.findOne({uuid: request.params.uuid});
let status = request.body.status as string;

if (!user) {
response.status(400).json({
"error": `No such user with id ${request.params.uuid}`
});
return;
}

try {
await updateUserStatus(user, status);
await user.save();
response.status(200).json({
"success": true
});
}
catch (err) {
console.error(err);
response.status(500).json({
"error": "An error occurred while changing user status"
});
}
});

async function updateUserStatus(user: IUserMongoose, status: string): Promise<void> {
if (status === "no-decision") {
// Clear all confirmation data
Expand Down

0 comments on commit d1440b0

Please sign in to comment.