From 610fd8bac84b44a4dd0423b72580bb2c8bd5af17 Mon Sep 17 00:00:00 2001 From: jvedrson Date: Thu, 4 Jul 2024 13:52:26 -0400 Subject: [PATCH] feat: get workspace user information --- src/app/routes/bridge.ts | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/app/routes/bridge.ts b/src/app/routes/bridge.ts index 54039b17..f8b21cf8 100644 --- a/src/app/routes/bridge.ts +++ b/src/app/routes/bridge.ts @@ -2,6 +2,7 @@ import { Router, Request, Response } from 'express'; import { passportAuth } from '../middleware/passport'; import { UserAttributes } from '../models/user'; +import createHttpError from 'http-errors'; type AuthorizedRequest = Request & { user: UserAttributes }; @@ -13,19 +14,41 @@ class BridgeController { } async getUsage(req: Request, res: Response) { - const usage = await this.service.User.getUsage((req as AuthorizedRequest).user); + let user = (req as AuthorizedRequest).user; + const { workspaceUserId } = req.query; + + if (workspaceUserId) { + user = await this.service.User.FindUserByUuid(workspaceUserId).catch(() => { + throw createHttpError(404, 'WorkspaceUser not found'); + }); + } + + const usage = await this.service.User.getUsage(user); res.status(200).send(usage); } async getLimit(req: Request, res: Response) { - const { + let { bridgeUser, userId: bridgePass, updatedAt, uuid } = (req as AuthorizedRequest).user; + const { workspaceUserId } = req.query; + + if (workspaceUserId) { + const workspaceUser = await this.service.User.FindUserByUuid(workspaceUserId).catch(() => { + throw createHttpError(404, 'WorkspaceUser not found'); + }); + + bridgeUser = workspaceUser.username; + bridgePass = workspaceUser.userId; + uuid = workspaceUser.uuid; + updatedAt = workspaceUser.updatedAt; + } + const limit = await this.service.Limit.getLimit( bridgeUser, bridgePass,