@laboratory-one/api-components 0.0.7 → 0.0.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@laboratory-one/api-components",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "API components for Laboratory One",
5
5
  "author": "Laboratory One",
6
6
  "private": false,
@@ -1,4 +1,4 @@
1
- import { IsOptional, IsString } from 'class-validator';
1
+ import { IsNumber, IsOptional, IsString } from 'class-validator';
2
2
  import { ApiProperty } from '@nestjs/swagger';
3
3
 
4
4
  export class UpdateUserRequestDto {
@@ -18,7 +18,7 @@ export class UpdateUserRequestDto {
18
18
  pushToken?: string | undefined;
19
19
 
20
20
  @IsOptional()
21
- @IsString()
21
+ @IsNumber()
22
22
  @ApiProperty()
23
- tz?: string | undefined;
23
+ tz?: number | undefined;
24
24
  }
@@ -23,7 +23,7 @@ import {
23
23
  cleanString,
24
24
  cleanStringAndLowercase,
25
25
  handleError,
26
- tzToInt,
26
+ utcOffsetToHours,
27
27
  } from '../utils';
28
28
  import { AuthGuard } from '../guard';
29
29
 
@@ -152,13 +152,13 @@ export class UserController {
152
152
  ? cleanStringAndLowercase(dto.fullName)
153
153
  : undefined,
154
154
  pushToken: dto.pushToken ? cleanString(dto.pushToken) : undefined,
155
- tz: dto.tz ? tzToInt(dto.tz) : undefined,
155
+ tz: dto.tz ? utcOffsetToHours(dto.tz) : undefined,
156
156
  };
157
157
 
158
- const user: User = await this.userService.update(req.user.userId, {
159
- ...cleanDto,
160
- tz: parseInt(cleanDto.tz, 10),
161
- });
158
+ const user: User = await this.userService.update(
159
+ req.user.userId,
160
+ cleanDto,
161
+ );
162
162
 
163
163
  if (user.fullName && user.phoneNumber) {
164
164
  await this.userService.update(req.user.userId, {
@@ -2,12 +2,6 @@ export const cleanString = (str: string): string => {
2
2
  return str.trim();
3
3
  };
4
4
 
5
- export const tzToInt = (str: string): string => {
6
- const trimmed = cleanString(str);
7
- const split = trimmed.split(':');
8
- return split[0];
9
- };
10
-
11
5
  export const cleanStringAndLowercase = (str: string): string => {
12
6
  const trimmed: string = cleanString(str);
13
7
  return trimmed.toLowerCase();
@@ -26,3 +20,13 @@ export const cleanPhoneNumber = (str: string): string => {
26
20
 
27
21
  return `+1${trimmed}`;
28
22
  };
23
+
24
+ export const utcOffsetToHours = (utcOffset: number): number => {
25
+ const hours = Math.floor(utcOffset / 60);
26
+
27
+ if (hours > 0) {
28
+ return 24 - hours;
29
+ }
30
+
31
+ return Math.abs(hours);
32
+ };