Inject
TSXinject
1import {
2 ContainerRegistryManager,
3 UserService,
4 Inject,
5 Service,
6} from "@quan-erp/shared-backend-core";
7
8@Service()
9export class MyPluginService {
10 @Inject(UserService, ContainerRegistryManager.BUILTIN_PLUGIN)
11 private userService: UserService;
12}Lookup methods
Resolve users without re-querying the user table from your plugin.
- findById(id: string): Promise<UserResponsePayload | null> — user by string id
- findByUserId(id: number, includePassword = false) — user by numeric id; set includePassword only when verifying credentials
- findByIds(ids: number[]): Promise<UserResponsePayload[]> — batch lookup
- findByUsername(username: string, includePassword = false) — login-name lookup
- find({ skip, limit, search }): Promise<UserEntity[] | null> — paginated list; search matches name/username
TSXlookup
1import {
2 ContainerRegistryManager,
3 Inject,
4 Service,
5 UserService,
6} from "@quan-erp/shared-backend-core";
7
8@Service()
9export class OrderAssignService {
10 @Inject(UserService, ContainerRegistryManager.BUILTIN_PLUGIN)
11 private userService: UserService;
12
13 async resolveAssignee(userId: number) {
14 const user = await this.userService.findByUserId(userId);
15 if (!user) throw new Error("User not found");
16 return user;
17 }
18
19 async searchStaff(q: string) {
20 return this.userService.find({ skip: 0, limit: 20, search: q });
21 }
22}Create / update methods
- create(user: CreateUserDto) — create user (username, name, password, roleId, isOwner, optional tags)
- update(id: string, data: UpdateUserPayload) — patch user fields
- setActive(userId: number, flag: boolean) — enable or disable a user account
- changePassword(data: ChangePasswordRequestPayload) — change password with current password check
- resetPassword(data: ResetPasswordRequestPayload) — admin/reset flow password reset
TSXcreate
1import {
2 ContainerRegistryManager,
3 Inject,
4 Service,
5 UserService,
6} from "@quan-erp/shared-backend-core";
7
8@Service()
9export class StaffOnboardService {
10 @Inject(UserService, ContainerRegistryManager.BUILTIN_PLUGIN)
11 private userService: UserService;
12
13 async onboard() {
14 await this.userService.create({
15 username: "cashier01",
16 name: "Cashier One",
17 password: "temporary-password",
18 roleId: 2,
19 isOwner: false,
20 });
21 }
22}Auth & session methods
Prefer these for sign-in flows instead of issuing tokens yourself.
- signin({ username, password }, info?) — returns access/refresh tokens; optional ipAddress / device metadata
- refreshToken(refreshToken: string) — rotate access token from a valid refresh token
- checkToken(refreshToken: string): Promise<boolean> — whether the refresh token is still valid
- signout(refreshToken: string): Promise<void> — invalidate one refresh session
- getLoginDevices({ userId, currentRefreshToken?, skip, limit, manager? }) — list active devices/sessions
- logoutOtherDevice(ids: number[], option?) — revoke selected device session ids
- logoutAllDevices(userId: number, option?) — revoke every session for a user
TSXsignin
1import {
2 ContainerRegistryManager,
3 Inject,
4 Service,
5 UserService,
6} from "@quan-erp/shared-backend-core";
7
8@Service()
9export class AuthFacadeService {
10 @Inject(UserService, ContainerRegistryManager.BUILTIN_PLUGIN)
11 private userService: UserService;
12
13 async login(username: string, password: string) {
14 return this.userService.signin(
15 { username, password },
16 { ipAddress: "127.0.0.1", device: "web" }
17 );
18 }
19
20 async logoutEverywhere(userId: number) {
21 await this.userService.logoutAllDevices(userId);
22 }
23}