@managemint-solutions/sdk 0.45.0 → 0.50.0

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.
package/dist/users/dto.js CHANGED
@@ -94,6 +94,8 @@ class GetUsersQueryDto {
94
94
  page_size = 10;
95
95
  // Comma-joined booleans on the wire, e.g. "true,false". Absent = all users.
96
96
  active_in;
97
+ // Still v4: a manager is a `users.mms_id`, which is the GoTrue auth uid (see UserIdDto).
98
+ manager_id;
97
99
  }
98
100
  exports.GetUsersQueryDto = GetUsersQueryDto;
99
101
  __decorate([
@@ -126,6 +128,12 @@ __decorate([
126
128
  (0, class_validator_1.IsBoolean)({ each: true, message: 'Active filter values must be booleans' }),
127
129
  __metadata("design:type", Object)
128
130
  ], GetUsersQueryDto.prototype, "active_in", void 0);
131
+ __decorate([
132
+ (0, class_validator_1.IsOptional)(),
133
+ (0, validators_1.IsNullable)(),
134
+ (0, class_validator_1.IsUUID)('4', { message: 'Invalid manager ID format' }),
135
+ __metadata("design:type", Object)
136
+ ], GetUsersQueryDto.prototype, "manager_id", void 0);
129
137
  class UpdateUserDto {
130
138
  name;
131
139
  surname;
@@ -138,6 +146,7 @@ class UpdateUserDto {
138
146
  job_title;
139
147
  manager_id;
140
148
  secondary_manager_id;
149
+ working_days;
141
150
  social_facebook;
142
151
  social_linkedin;
143
152
  social_twitter;
@@ -216,6 +225,17 @@ __decorate([
216
225
  (0, class_validator_1.IsUUID)('4', { message: 'Invalid secondary manager ID format' }),
217
226
  __metadata("design:type", Object)
218
227
  ], UpdateUserDto.prototype, "secondary_manager_id", void 0);
228
+ __decorate([
229
+ (0, class_validator_1.IsOptional)(),
230
+ (0, class_validator_1.IsArray)({ message: 'Working days must be a list of weekdays' }),
231
+ (0, class_validator_1.ArrayMinSize)(1, { message: 'Choose at least one working day' }),
232
+ (0, class_validator_1.ArrayMaxSize)(7, { message: 'A week has seven days' }),
233
+ (0, class_validator_1.ArrayUnique)({ message: 'Each working day may appear once' }),
234
+ (0, class_validator_1.IsInt)({ each: true, message: 'Working days are weekday numbers' }),
235
+ (0, class_validator_1.Min)(1, { each: true, message: 'Working days run from 1 (Monday) to 7 (Sunday)' }),
236
+ (0, class_validator_1.Max)(7, { each: true, message: 'Working days run from 1 (Monday) to 7 (Sunday)' }),
237
+ __metadata("design:type", Array)
238
+ ], UpdateUserDto.prototype, "working_days", void 0);
219
239
  __decorate([
220
240
  (0, class_validator_1.IsOptional)(),
221
241
  (0, validators_1.EmptyToNull)(),
@@ -5,6 +5,13 @@ import type { TypedSupabaseClient } from '../client';
5
5
  import type { GetUsersQueryDto } from './dto';
6
6
  export * from './dto';
7
7
  export * from './paths';
8
+ /** What leave needs to know about someone's employment. Dates are Johannesburg calendar dates. */
9
+ export type UserEmploymentRow = UserIdentity & {
10
+ active: boolean;
11
+ start_date: string;
12
+ end_date: string | null;
13
+ working_days: number[];
14
+ };
8
15
  /** The full users row. The api resolves its manager/created_by/last_updated_by ids into identities. */
9
16
  export type UserRow = Record<string, unknown> & {
10
17
  mms_id: string;
@@ -33,8 +40,11 @@ export declare class UsersResource {
33
40
  * `active` is not consulted: a deactivated report's history stays visible to their manager.
34
41
  */
35
42
  idsManagedBy(managerId: string): Promise<string[]>;
36
- /** The ids of every active member - who the leave rollover grants a new period to. */
37
- activeIds(): Promise<string[]>;
43
+ /**
44
+ * Employment details for leave: start and end as calendar dates in Johannesburg (the columns
45
+ * are timestamps), and the working week. Everyone in the organization, or just `userIds`.
46
+ */
47
+ employment(userIds?: string[]): Promise<UserEmploymentRow[]>;
38
48
  /** Seats in use. Counts rows rather than fetching them. */
39
49
  activeCount(): Promise<number>;
40
50
  isActive(userId: string): Promise<boolean>;
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.UsersResource = void 0;
18
18
  const enum_1 = require("@managemint-solutions/entities/audit-trail/enum");
19
+ const working_days_1 = require("../leave/working-days");
19
20
  const audit_1 = require("../audit");
20
21
  const errors_1 = require("../errors");
21
22
  const paths_1 = require("../supporting-files/paths");
@@ -58,6 +59,10 @@ class UsersResource {
58
59
  if (trimmedSearch) {
59
60
  usersQuery = usersQuery.or((0, transforms_1.orIlike)(['name', 'surname', 'email'], trimmedSearch));
60
61
  }
62
+ // Either manager line, as `idsManagedBy` reads it. PostgREST ANDs this with the search.
63
+ if (query.manager_id) {
64
+ usersQuery = usersQuery.or(`manager_id.eq.${query.manager_id},secondary_manager_id.eq.${query.manager_id}`);
65
+ }
61
66
  const { data, error, count } = await usersQuery;
62
67
  if (error)
63
68
  throw (0, errors_1.mapPostgrestError)(error);
@@ -107,16 +112,26 @@ class UsersResource {
107
112
  throw (0, errors_1.mapPostgrestError)(error);
108
113
  return (data ?? []).map((row) => row.mms_id);
109
114
  }
110
- /** The ids of every active member - who the leave rollover grants a new period to. */
111
- async activeIds() {
112
- const { data, error } = await this.supabase
115
+ /**
116
+ * Employment details for leave: start and end as calendar dates in Johannesburg (the columns
117
+ * are timestamps), and the working week. Everyone in the organization, or just `userIds`.
118
+ */
119
+ async employment(userIds) {
120
+ let employmentQuery = this.supabase
113
121
  .from('users')
114
- .select('mms_id')
115
- .eq('organization_id', this.auth.organization_id)
116
- .eq('active', true);
122
+ .select('mms_id, name, surname, email, profile_image, active, start_date, end_date, working_days')
123
+ .eq('organization_id', this.auth.organization_id);
124
+ if (userIds) {
125
+ employmentQuery = employmentQuery.in('mms_id', userIds);
126
+ }
127
+ const { data, error } = await employmentQuery;
117
128
  if (error)
118
129
  throw (0, errors_1.mapPostgrestError)(error);
119
- return (data ?? []).map((row) => row.mms_id);
130
+ return (data ?? []).map((row) => ({
131
+ ...row,
132
+ start_date: (0, working_days_1.todayInJohannesburg)(new Date(row.start_date)),
133
+ end_date: row.end_date ? (0, working_days_1.todayInJohannesburg)(new Date(row.end_date)) : null,
134
+ }));
120
135
  }
121
136
  /** Seats in use. Counts rows rather than fetching them. */
122
137
  async activeCount() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@managemint-solutions/sdk",
3
- "version": "0.45.0",
3
+ "version": "0.50.0",
4
4
  "description": "Typed Supabase data-access SDK for ManageMint Solutions",
5
5
  "license": "UNLICENSED",
6
6
  "author": "Scott Bebington <scottbebington@gmail.com>",
@@ -51,7 +51,7 @@
51
51
  "testEnvironment": "node"
52
52
  },
53
53
  "dependencies": {
54
- "@managemint-solutions/entities": "^1.28.0"
54
+ "@managemint-solutions/entities": "^1.33.0"
55
55
  },
56
56
  "peerDependencies": {
57
57
  "@nestjs/common": "^11.0.0",