Add endpoints on pusher to resolve wokas

This commit is contained in:
Alexis Faizeau
2022-02-17 15:02:11 +01:00
committed by David Négrier
parent f993aa4f5a
commit 2161a40e05
12 changed files with 1880 additions and 1 deletions
@@ -69,7 +69,7 @@ export class AuthenticateController extends BaseHttpController {
//if not nonce and code, user connected in anonymous
//get data with identifier and return token
if (!code && !nonce) {
return res.json(JSON.stringify({ ...resUserData, authToken: token }));
return res.json({ ...resUserData, authToken: token });
}
console.error("Token cannot to be check on OpenId provider");
res.status(500);
@@ -0,0 +1,47 @@
import { hasToken } from "../Middleware/HasToken";
import { BaseHttpController } from "./BaseHttpController";
import { ADMIN_API_URL } from "../Enum/EnvironmentVariable";
import { adminWokaService } from "..//Services/AdminWokaService";
import { localWokaService } from "..//Services/LocalWokaService";
import { WokaServiceInterface } from "src/Services/WokaServiceInterface";
import { Server } from "hyper-express";
export class WokaListController extends BaseHttpController {
private wokaService: WokaServiceInterface;
constructor(app: Server) {
super(app);
this.wokaService = ADMIN_API_URL ? adminWokaService : localWokaService;
}
routes() {
// eslint-disable-next-line @typescript-eslint/no-misused-promises
this.app.get("/woka-list", { middlewares: [hasToken] }, async (req, res) => {
const token = req.header("Authorization");
const wokaList = await this.wokaService.getWokaList(token);
if (!wokaList) {
return res.status(500).send("Error on getting woka list");
}
return res.status(200).json(wokaList);
});
// eslint-disable-next-line @typescript-eslint/no-misused-promises
this.app.post("/woka-details", async (req, res) => {
const body = await req.json();
if (!body || !body.textureIds) {
return res.status(400);
}
const textureIds = body.textureIds;
const wokaDetails = await this.wokaService.fetchWokaDetails(textureIds);
if (!wokaDetails) {
return res.json({ details: [] });
}
return res.json(wokaDetails);
});
}
}