@loomcore/api 0.2.23 → 0.2.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,6 +9,7 @@ export interface UsersControllerOptions {
9
9
  userService?: UserService;
10
10
  userSpec?: IModelSpec;
11
11
  publicUserSpec?: IModelSpec;
12
+ routeAuth?: MethodAuth;
12
13
  }
13
14
  export declare class UsersController extends ApiController<IUser> {
14
15
  userService: UserService;
@@ -13,7 +13,7 @@ export class UsersController extends ApiController {
13
13
  const userSpec = options.userSpec ?? UserSpec;
14
14
  const publicUserSpec = options.publicUserSpec ?? PublicUserSpec;
15
15
  const userService = options.userService ?? new UserService(database, userSpec);
16
- super("users", app, userService, usersRouteAuth, "user", userSpec, publicUserSpec);
16
+ super("users", app, userService, options.routeAuth ?? usersRouteAuth, "user", userSpec, publicUserSpec);
17
17
  this.userService = userService;
18
18
  }
19
19
  }
@@ -1,4 +1,4 @@
1
- import { type IModelSpec, type IQueryOptions, type IUser, type IUserContext } from "@loomcore/common/models";
1
+ import { type IModelSpec, type IPagedResult, type IQueryOptions, type IUser, type IUserContext } from "@loomcore/common/models";
2
2
  import type { AppIdType } from "@loomcore/common/types";
3
3
  import type { IDatabase } from "../databases/models/index.js";
4
4
  import { MultiTenantApiService } from "./multi-tenant-api.service.js";
@@ -7,6 +7,10 @@ export declare class UserService extends MultiTenantApiService<IUser> {
7
7
  private isAdmin;
8
8
  private assertAdmin;
9
9
  private assertSelfOrAdmin;
10
+ getById(userContext: IUserContext, id: AppIdType): Promise<IUser>;
11
+ get(userContext: IUserContext, queryOptions?: IQueryOptions): Promise<IPagedResult<IUser>>;
12
+ getAll(userContext: IUserContext): Promise<IUser[]>;
13
+ getCount(userContext: IUserContext): Promise<number>;
10
14
  fullUpdateById(_userContext: IUserContext, _id: AppIdType, _entity: IUser): Promise<IUser>;
11
15
  update(userContext: IUserContext, queryObject: IQueryOptions, entity: Partial<IUser>): Promise<IUser[]>;
12
16
  batchUpdate(userContext: IUserContext, entities: Partial<IUser>[]): Promise<IUser[]>;
@@ -23,6 +23,22 @@ export class UserService extends MultiTenantApiService {
23
23
  throw new UnauthorizedError();
24
24
  }
25
25
  }
26
+ async getById(userContext, id) {
27
+ this.assertSelfOrAdmin(userContext, id);
28
+ return super.getById(userContext, id);
29
+ }
30
+ async get(userContext, queryOptions) {
31
+ this.assertAdmin(userContext);
32
+ return super.get(userContext, queryOptions);
33
+ }
34
+ async getAll(userContext) {
35
+ this.assertAdmin(userContext);
36
+ return super.getAll(userContext);
37
+ }
38
+ async getCount(userContext) {
39
+ this.assertAdmin(userContext);
40
+ return super.getCount(userContext);
41
+ }
26
42
  async fullUpdateById(_userContext, _id, _entity) {
27
43
  throw new ServerError("User full update is not allowed.");
28
44
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loomcore/api",
3
- "version": "0.2.23",
3
+ "version": "0.2.24",
4
4
  "private": false,
5
5
  "description": "Loom Core Api - An opinionated Node.js api using Typescript, Express, and MongoDb or PostgreSQL",
6
6
  "scripts": {