-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathusers.service.ts
29 lines (27 loc) · 1001 Bytes
/
users.service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { Inject, Injectable, Scope } from "@nestjs/common";
import { ClientProxy } from "@nestjs/microservices";
import { CONTEXT } from "@nestjs/graphql";
import { RequestFunction } from "common/RequestFunction";
import { UserGqlDto } from "common/graphql/user-gql.dto";
@Injectable({ scope: Scope.REQUEST })
export class UsersService {
private readonly tenantId: any;
constructor(
@Inject("USERS_SERVICE") private readonly usersServiceClient: ClientProxy,
@Inject(CONTEXT) private readonly context: any,
) {
if (this.context.req.headers["x-tenant-id"] !== undefined) {
this.tenantId = this.context.req.headers["x-tenant-id"]
? `tenant_${this.context.req.headers["x-tenant-id"]}`
: "dev";
}
}
getAllUsers = async (): Promise<UserGqlDto[]> => {
const res: any = await new RequestFunction(
this.usersServiceClient,
"get_all_users",
{ tenantId: this.tenantId },
).request();
return res;
};
}