Skip to content

Commit

Permalink
feat: get workspace user information
Browse files Browse the repository at this point in the history
  • Loading branch information
jvedrson committed Jul 4, 2024
1 parent 2f29354 commit 610fd8b
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions src/app/routes/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

Expand All @@ -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,
Expand Down

0 comments on commit 610fd8b

Please sign in to comment.