@laboratory-one/api-components 0.0.12 → 0.0.13
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/cjs/auth/auth.service.d.ts +3 -1
- package/dist/cjs/auth/auth.service.d.ts.map +1 -1
- package/dist/cjs/auth/auth.service.js +5 -1
- package/dist/cjs/auth/auth.service.js.map +1 -1
- package/dist/cjs/user/dtos/delete-user.request.dto.d.ts +4 -0
- package/dist/cjs/user/dtos/delete-user.request.dto.d.ts.map +1 -0
- package/dist/cjs/user/dtos/delete-user.request.dto.js +15 -0
- package/dist/cjs/user/dtos/delete-user.request.dto.js.map +1 -0
- package/dist/cjs/user/dtos/index.d.ts +1 -0
- package/dist/cjs/user/dtos/index.d.ts.map +1 -1
- package/dist/cjs/user/dtos/index.js +1 -0
- package/dist/cjs/user/dtos/index.js.map +1 -1
- package/dist/cjs/user/user.controller.d.ts.map +1 -1
- package/dist/cjs/user/user.controller.js +4 -13
- package/dist/cjs/user/user.controller.js.map +1 -1
- package/dist/cjs/utils/index.d.ts +1 -0
- package/dist/cjs/utils/index.d.ts.map +1 -1
- package/dist/cjs/utils/index.js +1 -0
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/cjs/utils/noop.util.d.ts +2 -1
- package/dist/cjs/utils/noop.util.d.ts.map +1 -1
- package/dist/cjs/utils/noop.util.js +5 -3
- package/dist/cjs/utils/noop.util.js.map +1 -1
- package/dist/esm/auth/auth.service.d.ts +3 -1
- package/dist/esm/auth/auth.service.d.ts.map +1 -1
- package/dist/esm/auth/auth.service.js +5 -1
- package/dist/esm/auth/auth.service.js.map +1 -1
- package/dist/esm/user/dtos/delete-user.request.dto.d.ts +4 -0
- package/dist/esm/user/dtos/delete-user.request.dto.d.ts.map +1 -0
- package/dist/esm/user/dtos/delete-user.request.dto.js +11 -0
- package/dist/esm/user/dtos/delete-user.request.dto.js.map +1 -0
- package/dist/esm/user/dtos/index.d.ts +1 -0
- package/dist/esm/user/dtos/index.d.ts.map +1 -1
- package/dist/esm/user/dtos/index.js +1 -0
- package/dist/esm/user/dtos/index.js.map +1 -1
- package/dist/esm/user/user.controller.d.ts.map +1 -1
- package/dist/esm/user/user.controller.js +4 -13
- package/dist/esm/user/user.controller.js.map +1 -1
- package/dist/esm/utils/index.d.ts +1 -0
- package/dist/esm/utils/index.d.ts.map +1 -1
- package/dist/esm/utils/index.js +1 -0
- package/dist/esm/utils/index.js.map +1 -1
- package/dist/esm/utils/noop.util.d.ts +2 -1
- package/dist/esm/utils/noop.util.d.ts.map +1 -1
- package/dist/esm/utils/noop.util.js +2 -1
- package/dist/esm/utils/noop.util.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/auth/auth.service.ts +12 -3
- package/src/user/dtos/delete-user.request.dto.ts +8 -0
- package/src/user/dtos/index.ts +1 -0
- package/src/user/user.controller.ts +6 -11
- package/src/utils/index.ts +1 -0
- package/src/utils/noop.util.ts +2 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as stytch from 'stytch';
|
|
1
2
|
import { ConfigService } from '@nestjs/config';
|
|
2
3
|
import { RegisterRequestDto } from '../user/dtos/register.request.dto';
|
|
3
4
|
export declare class AuthService {
|
|
@@ -5,7 +6,8 @@ export declare class AuthService {
|
|
|
5
6
|
private readonly logger;
|
|
6
7
|
private authClient;
|
|
7
8
|
constructor(configService: ConfigService);
|
|
8
|
-
signup(data: RegisterRequestDto): Promise<
|
|
9
|
+
signup(data: RegisterRequestDto): Promise<stytch.PasswordsCreateResponse>;
|
|
9
10
|
login(data: RegisterRequestDto): Promise<boolean>;
|
|
11
|
+
delete(externalId: string): Promise<void>;
|
|
10
12
|
}
|
|
11
13
|
//# sourceMappingURL=auth.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.service.d.ts","sourceRoot":"/","sources":["auth/auth.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"auth.service.d.ts","sourceRoot":"/","sources":["auth/auth.service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAGvE,qBACa,WAAW;IAIV,OAAO,CAAC,aAAa;IAHjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAwC;IAC/D,OAAO,CAAC,UAAU,CAAgB;gBAEd,aAAa,EAAE,aAAa;IAW1C,MAAM,CACV,IAAI,EAAE,kBAAkB,GACvB,OAAO,CAAC,MAAM,CAAC,uBAAuB,CAAC;IASpC,KAAK,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,OAAO,CAAC;IAiBjD,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAKhD"}
|
|
@@ -22,7 +22,7 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
22
22
|
async signup(data) {
|
|
23
23
|
this.logger.debug('signup');
|
|
24
24
|
const res = await this.authClient.passwords.create(data);
|
|
25
|
-
return res
|
|
25
|
+
return res;
|
|
26
26
|
}
|
|
27
27
|
async login(data) {
|
|
28
28
|
this.logger.debug('login');
|
|
@@ -39,6 +39,10 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
+
async delete(externalId) {
|
|
43
|
+
this.logger.debug('delete');
|
|
44
|
+
await this.authClient.users.delete({ user_id: externalId });
|
|
45
|
+
}
|
|
42
46
|
};
|
|
43
47
|
exports.AuthService = AuthService;
|
|
44
48
|
exports.AuthService = AuthService = AuthService_1 = tslib_1.__decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.service.js","sourceRoot":"/","sources":["auth/auth.service.ts"],"names":[],"mappings":";;;;;AAAA,2CAAoD;AACpD,uDAAi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\nimport * as stytch from 'stytch';\nimport { ConfigService } from '@nestjs/config';\n\nimport { RegisterRequestDto } from '../user/dtos/register.request.dto';\nimport { handleError } from '../utils';\n\n@Injectable()\nexport class AuthService {\n private readonly logger: Logger = new Logger(AuthService.name);\n private authClient: stytch.Client;\n\n constructor(private configService: ConfigService) {\n this.authClient = new stytch.Client({\n project_id: this.configService.get<string>('STYTCH_PROJECT_ID'),\n secret: this.configService.get<string>('STYTCH_SECRET'),\n env:\n this.configService.get<string>('STYTCH_ENV') === 'test'\n ? stytch.envs.test\n : stytch.envs.live,\n });\n }\n\n async signup(\n data: RegisterRequestDto,\n ): Promise<stytch.PasswordsCreateResponse> {\n this.logger.debug('signup');\n\n const res: stytch.PasswordsCreateResponse =\n await this.authClient.passwords.create(data);\n\n return res;\n }\n\n async login(data: RegisterRequestDto): Promise<boolean> {\n this.logger.debug('login');\n\n try {\n const res = await this.authClient.passwords.authenticate(data);\n return res['status_code'] === 200;\n } catch (error: any) {\n if (error.error_type === 'email_not_found') {\n handleError('Email or password is wrong');\n }\n\n if (error.error_type === 'unauthorized_credentials') {\n handleError('Email or password is wrong');\n }\n }\n }\n\n async delete(externalId: string): Promise<void> {\n this.logger.debug('delete');\n\n await this.authClient.users.delete({ user_id: externalId });\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete-user.request.dto.d.ts","sourceRoot":"/","sources":["user/dtos/delete-user.request.dto.ts"],"names":[],"mappings":"AAGA,qBAAa,oBAAoB;IAG/B,KAAK,EAAE,MAAM,CAAC;CACf"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DeleteUserRequestDto = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const class_validator_1 = require("class-validator");
|
|
6
|
+
const swagger_1 = require("@nestjs/swagger");
|
|
7
|
+
class DeleteUserRequestDto {
|
|
8
|
+
}
|
|
9
|
+
exports.DeleteUserRequestDto = DeleteUserRequestDto;
|
|
10
|
+
tslib_1.__decorate([
|
|
11
|
+
(0, class_validator_1.IsString)(),
|
|
12
|
+
(0, swagger_1.ApiProperty)(),
|
|
13
|
+
tslib_1.__metadata("design:type", String)
|
|
14
|
+
], DeleteUserRequestDto.prototype, "email", void 0);
|
|
15
|
+
//# sourceMappingURL=delete-user.request.dto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete-user.request.dto.js","sourceRoot":"/","sources":["user/dtos/delete-user.request.dto.ts"],"names":[],"mappings":";;;;AAAA,qDAA2C;AAC3C,6CAA8C;AAE9C,MAAa,oBAAoB;CAIhC;AAJD,oDAIC;AADC;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,qBAAW,GAAE;;mDACA","sourcesContent":["import { IsString } from 'class-validator';\nimport { ApiProperty } from '@nestjs/swagger';\n\nexport class DeleteUserRequestDto {\n @IsString()\n @ApiProperty()\n email: string;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["user/dtos/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["user/dtos/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC"}
|
|
@@ -5,4 +5,5 @@ tslib_1.__exportStar(require("./get-user.response.dto"), exports);
|
|
|
5
5
|
tslib_1.__exportStar(require("./register.request.dto"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./register.response.dto"), exports);
|
|
7
7
|
tslib_1.__exportStar(require("./update-user.request.dto"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./delete-user.request.dto"), exports);
|
|
8
9
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["user/dtos/index.ts"],"names":[],"mappings":";;;AAAA,kEAAwC;AACxC,iEAAuC;AACvC,kEAAwC;AACxC,oEAA0C","sourcesContent":["export * from './get-user.response.dto';\nexport * from './register.request.dto';\nexport * from './register.response.dto';\nexport * from './update-user.request.dto';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["user/dtos/index.ts"],"names":[],"mappings":";;;AAAA,kEAAwC;AACxC,iEAAuC;AACvC,kEAAwC;AACxC,oEAA0C;AAC1C,oEAA0C","sourcesContent":["export * from './get-user.response.dto';\nexport * from './register.request.dto';\nexport * from './register.response.dto';\nexport * from './update-user.request.dto';\nexport * from './delete-user.request.dto';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.controller.d.ts","sourceRoot":"/","sources":["user/user.controller.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"user.controller.d.ts","sourceRoot":"/","sources":["user/user.controller.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAMzC,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAUnD,qBAEa,cAAc;IAEvB,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,UAAU;gBAHV,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,WAAW,EACxB,UAAU,EAAE,UAAU;IAS1B,MAAM,CAAS,GAAG,EAAE,kBAAkB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAqCrE,KAAK,CAAS,GAAG,EAAE,kBAAkB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAkCpE,OAAO,CAAY,GAAG,KAAA,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAmBpD,IAAI,CACA,GAAG,EAAE,oBAAoB,EACtB,GAAG,KAAA,GACb,OAAO,CAAC,kBAAkB,CAAC;IAoCxB,QAAQ,CAAY,GAAG,KAAA,GAAG,OAAO,CAAC,IAAI,CAAC;CAiB9C"}
|
|
@@ -27,22 +27,13 @@ let UserController = class UserController {
|
|
|
27
27
|
email: (0, utils_1.cleanStringAndLowercase)(dto.email),
|
|
28
28
|
password: (0, utils_1.cleanString)(dto.password),
|
|
29
29
|
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
(0, utils_1.handleError)('Error creating user');
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
catch (error) {
|
|
37
|
-
if (error === null || error === void 0 ? void 0 : error.error_message) {
|
|
38
|
-
(0, utils_1.handleError)(error.error_message);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
(0, utils_1.handleError)('Error creating user');
|
|
42
|
-
}
|
|
30
|
+
const res = await this.authService.signup(cleanedDTO);
|
|
31
|
+
if (!res) {
|
|
32
|
+
(0, utils_1.handleError)('Error creating user');
|
|
43
33
|
}
|
|
44
34
|
const user = await this.userService.create({
|
|
45
35
|
email: cleanedDTO.email,
|
|
36
|
+
externalId: res.user_id,
|
|
46
37
|
});
|
|
47
38
|
if (!user) {
|
|
48
39
|
(0, utils_1.handleError)('Error creating user');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.controller.js","sourceRoot":"/","sources":["user/user.controller.ts"],"names":[],"mappings":";;;;AAAA,2CAOwB;AACxB,qCAAyC;AACzC,6CAAuD;AACvD,2CAAwD;AAGxD,uDAAmD;AACnD,iDAA6C;AAC7C,wEAAkE;AAClE,4EAAsE;AACtE,wEAAmE;AACnE,sEAAiE;AACjE,uDAAmD;AACnD,oCAMkB;AAClB,oCAAqC;AAI9B,IAAM,cAAc,GAApB,MAAM,cAAc;IACzB,YACU,WAAwB,EACxB,WAAwB,EACxB,WAAwB,EACxB,UAAsB;QAHtB,gBAAW,GAAX,WAAW,CAAa;QACxB,gBAAW,GAAX,WAAW,CAAa;QACxB,gBAAW,GAAX,WAAW,CAAa;QACxB,eAAU,GAAV,UAAU,CAAY;IAC7B,CAAC;IAQE,AAAN,KAAK,CAAC,MAAM,CAAS,GAAuB;QAC1C,MAAM,UAAU,GAAuB;YACrC,KAAK,EAAE,IAAA,+BAAuB,EAAC,GAAG,CAAC,KAAK,CAAC;YACzC,QAAQ,EAAE,IAAA,mBAAW,EAAC,GAAG,CAAC,QAAQ,CAAC;SACpC,CAAC;QAEF,IAAI,CAAC;YACH,MAAM,GAAG,GAAY,MAAM,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;YAE/D,IAAI,CAAC,GAAG,EAAE,CAAC;gBACT,IAAA,mBAAW,EAAC,qBAAqB,CAAC,CAAC;YACrC,CAAC;QACH,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,IAAI,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,aAAa,EAAE,CAAC;gBACzB,IAAA,mBAAW,EAAC,KAAK,CAAC,aAAa,CAAC,CAAC;YACnC,CAAC;iBAAM,CAAC;gBACN,IAAA,mBAAW,EAAC,qBAAqB,CAAC,CAAC;YACrC,CAAC;QACH,C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C;QACX,MAAM,EAAE,GAAG;QACX,WAAW,EAAE,qBAAqB;QAClC,IAAI,EAAE,0CAAkB;KACzB,CAAC;IACa,mBAAA,IAAA,gBAAO,GAAE,CAAA;;;;6CAUvB;AASK;IAPL,IAAA,kBAAS,EAAC,iBAAS,CAAC;IACpB,IAAA,aAAI,EAAC,QAAQ,CAAC;IACd,IAAA,qBAAW,EAAC;QACX,MAAM,EAAE,GAAG;QACX,WAAW,EAAE,wBAAwB;QACrC,IAAI,EAAE,0CAAkB;KACzB,CAAC;IAEC,mBAAA,IAAA,aAAI,GAAE,CAAA;IACN,mBAAA,IAAA,gBAAO,GAAE,CAAA;;6CADG,8CAAoB;;0CA8BlC;AAQK;IANL,IAAA,kBAAS,EAAC,iBAAS,CAAC;IACpB,IAAA,aAAI,EAAC,UAAU,CAAC;IAChB,IAAA,qBAAW,EAAC;QACX,MAAM,EAAE,GAAG;QACX,WAAW,EAAE,sBAAsB;KACpC,CAAC;IACc,mBAAA,IAAA,gBAAO,GAAE,CAAA;;;;8CAgBxB;yBArKU,cAAc;IAF1B,IAAA,iBAAO,EAAC,MAAM,CAAC;IACf,IAAA,mBAAU,EAAC,MAAM,CAAC;6CAGM,0BAAW;QACX,0BAAW;QACX,0BAAW;QACZ,gBAAU;GALrB,cAAc,CAsK1B","sourcesContent":["import {\n Body,\n Controller,\n Get,\n Post,\n Request,\n UseGuards,\n} from '@nestjs/common';\nimport { JwtService } from '@nestjs/jwt';\nimport { ApiResponse, ApiTags } from '@nestjs/swagger';\nimport { OnboardingStatus, User } from '@prisma/client';\nimport { ExpoPushMessage } from 'expo-server-sdk';\n\nimport { AuthService } from '../auth/auth.service';\nimport { UserService } from './user.service';\nimport { GetUserResponseDto } from './dtos/get-user.response.dto';\nimport { UpdateUserRequestDto } from './dtos/update-user.request.dto';\nimport { RegisterResponseDto } from './dtos/register.response.dto';\nimport { RegisterRequestDto } from './dtos/register.request.dto';\nimport { PushService } from '../push/push.service';\nimport {\n cleanPhoneNumber,\n cleanString,\n cleanStringAndLowercase,\n handleError,\n utcOffsetToHours,\n} from '../utils';\nimport { AuthGuard } from '../guard';\n\n@ApiTags('User')\n@Controller('user')\nexport class UserController {\n constructor(\n private userService: UserService,\n private authService: AuthService,\n private pushService: PushService,\n private jwtService: JwtService,\n ) {}\n\n @Post('signup')\n @ApiResponse({\n status: 200,\n description: 'loginOrCreate successful',\n type: RegisterResponseDto,\n })\n async signup(@Body() dto: RegisterRequestDto): Promise<RegisterResponseDto> {\n const cleanedDTO: RegisterRequestDto = {\n email: cleanStringAndLowercase(dto.email),\n password: cleanString(dto.password),\n };\n\n try {\n const res: boolean = await this.authService.signup(cleanedDTO);\n\n if (!res) {\n handleError('Error creating user');\n }\n } catch (error: any) {\n if (error?.error_message) {\n handleError(error.error_message);\n } else {\n handleError('Error creating user');\n }\n }\n\n const user: User = await this.userService.create({\n email: cleanedDTO.email,\n });\n\n if (!user) {\n handleError('Error creating user');\n }\n\n const payload = { userId: user.id };\n const token: string = await this.jwtService.signAsync(payload);\n\n return {\n ...user,\n token,\n };\n }\n\n @Post('login')\n @ApiResponse({\n status: 200,\n description: 'loginOrCreate successful',\n type: RegisterResponseDto,\n })\n async login(@Body() dto: RegisterRequestDto): Promise<RegisterResponseDto> {\n const cleanedDTO: RegisterRequestDto = {\n email: cleanStringAndLowercase(dto.email),\n password: dto.password.trim(),\n };\n\n const res: boolean = await this.authService.login(cleanedDTO);\n\n if (!res) {\n handleError('Error logging in');\n }\n\n const user: User = await this.userService.findOneByEmail(cleanedDTO.email);\n\n if (!user) {\n handleError('Error logging in');\n }\n\n const payload = { userId: user.id };\n const token: string = await this.jwtService.signAsync(payload);\n\n return {\n ...user,\n token,\n };\n }\n\n @UseGuards(AuthGuard)\n @Get('self')\n @ApiResponse({\n status: 200,\n description: 'get self successful',\n type: GetUserResponseDto,\n })\n async getSelf(@Request() req): Promise<GetUserResponseDto> {\n try {\n const user: User = await this.userService.findOneByUserId(\n req.user.userId,\n );\n\n return user as GetUserResponseDto;\n } catch (error) {\n handleError(error);\n }\n }\n\n @UseGuards(AuthGuard)\n @Post('update')\n @ApiResponse({\n status: 200,\n description: 'update user successful',\n type: GetUserResponseDto,\n })\n async edit(\n @Body() dto: UpdateUserRequestDto,\n @Request() req,\n ): Promise<GetUserResponseDto> {\n try {\n const cleanDto: UpdateUserRequestDto = {\n phoneNumber: dto.phoneNumber\n ? cleanPhoneNumber(dto.phoneNumber)\n : undefined,\n fullName: dto.fullName\n ? cleanStringAndLowercase(dto.fullName)\n : undefined,\n pushToken: dto.pushToken ? cleanString(dto.pushToken) : undefined,\n tz: dto.tz ? utcOffsetToHours(dto.tz) : undefined,\n };\n\n const user: User = await this.userService.update(\n req.user.userId,\n cleanDto,\n );\n\n if (user.fullName && user.phoneNumber) {\n await this.userService.update(req.user.userId, {\n onboardingStatus: OnboardingStatus.COMPLETED,\n });\n }\n\n return user as GetUserResponseDto;\n } catch (error) {\n handleError(error);\n }\n }\n\n @UseGuards(AuthGuard)\n @Post('pushTest')\n @ApiResponse({\n status: 200,\n description: 'push test successful',\n })\n async pushTest(@Request() req): Promise<void> {\n try {\n const user: User = await this.userService.findOneByUserId(\n req.user.userId,\n );\n\n if (user.pushToken) {\n const messages: ExpoPushMessage[] = this.pushService.createMessages({\n body: 'Test push',\n pushTokens: [user.pushToken],\n });\n await this.pushService.sendMessages(messages);\n }\n } catch (error) {\n handleError(error);\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"user.controller.js","sourceRoot":"/","sources":["user/user.controller.ts"],"names":[],"mappings":";;;;AAAA,2CAOwB;AACxB,qCAAyC;AACzC,6CAAuD;AACvD,2CAAwD;AAIxD,uDAAmD;AACnD,iDAA6C;AAC7C,wEAAkE;AAClE,4EAAsE;AACtE,wEAAmE;AACnE,sEAAiE;AACjE,uDAAmD;AACnD,oCAMkB;AAClB,oCAAqC;AAI9B,IAAM,cAAc,GAApB,MAAM,cAAc;IACzB,YACU,WAAwB,EACxB,WAAwB,EACxB,WAAwB,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1B,IAAA,iBAAO,EAAC,MAAM,CAAC;IACf,IAAA,mBAAU,EAAC,MAAM,CAAC;6CAGM,0BAAW;QACX,0BAAW;QACX,0BAAW;QACZ,gBAAU;GALrB,cAAc,CAgK1B","sourcesContent":["import {\n Body,\n Controller,\n Get,\n Post,\n Request,\n UseGuards,\n} from '@nestjs/common';\nimport { JwtService } from '@nestjs/jwt';\nimport { ApiResponse, ApiTags } from '@nestjs/swagger';\nimport { OnboardingStatus, User } from '@prisma/client';\nimport { ExpoPushMessage } from 'expo-server-sdk';\nimport * as stytch from 'stytch';\n\nimport { AuthService } from '../auth/auth.service';\nimport { UserService } from './user.service';\nimport { GetUserResponseDto } from './dtos/get-user.response.dto';\nimport { UpdateUserRequestDto } from './dtos/update-user.request.dto';\nimport { RegisterResponseDto } from './dtos/register.response.dto';\nimport { RegisterRequestDto } from './dtos/register.request.dto';\nimport { PushService } from '../push/push.service';\nimport {\n cleanPhoneNumber,\n cleanString,\n cleanStringAndLowercase,\n handleError,\n utcOffsetToHours,\n} from '../utils';\nimport { AuthGuard } from '../guard';\n\n@ApiTags('User')\n@Controller('user')\nexport class UserController {\n constructor(\n private userService: UserService,\n private authService: AuthService,\n private pushService: PushService,\n private jwtService: JwtService,\n ) {}\n\n @Post('signup')\n @ApiResponse({\n status: 200,\n description: 'loginOrCreate successful',\n type: RegisterResponseDto,\n })\n async signup(@Body() dto: RegisterRequestDto): Promise<RegisterResponseDto> {\n const cleanedDTO: RegisterRequestDto = {\n email: cleanStringAndLowercase(dto.email),\n password: cleanString(dto.password),\n };\n\n const res: stytch.PasswordsCreateResponse =\n await this.authService.signup(cleanedDTO);\n\n if (!res) {\n handleError('Error creating user');\n }\n\n const user: User = await this.userService.create({\n email: cleanedDTO.email,\n externalId: res.user_id,\n });\n\n if (!user) {\n handleError('Error creating user');\n }\n\n const payload = { userId: user.id };\n const token: string = await this.jwtService.signAsync(payload);\n\n return {\n ...user,\n token,\n };\n }\n\n @Post('login')\n @ApiResponse({\n status: 200,\n description: 'loginOrCreate successful',\n type: RegisterResponseDto,\n })\n async login(@Body() dto: RegisterRequestDto): Promise<RegisterResponseDto> {\n const cleanedDTO: RegisterRequestDto = {\n email: cleanStringAndLowercase(dto.email),\n password: dto.password.trim(),\n };\n\n const res: boolean = await this.authService.login(cleanedDTO);\n\n if (!res) {\n handleError('Error logging in');\n }\n\n const user: User = await this.userService.findOneByEmail(cleanedDTO.email);\n\n if (!user) {\n handleError('Error logging in');\n }\n\n const payload = { userId: user.id };\n const token: string = await this.jwtService.signAsync(payload);\n\n return {\n ...user,\n token,\n };\n }\n\n @UseGuards(AuthGuard)\n @Get('self')\n @ApiResponse({\n status: 200,\n description: 'get self successful',\n type: GetUserResponseDto,\n })\n async getSelf(@Request() req): Promise<GetUserResponseDto> {\n try {\n const user: User = await this.userService.findOneByUserId(\n req.user.userId,\n );\n\n return user as GetUserResponseDto;\n } catch (error) {\n handleError(error);\n }\n }\n\n @UseGuards(AuthGuard)\n @Post('update')\n @ApiResponse({\n status: 200,\n description: 'update user successful',\n type: GetUserResponseDto,\n })\n async edit(\n @Body() dto: UpdateUserRequestDto,\n @Request() req,\n ): Promise<GetUserResponseDto> {\n try {\n const cleanDto: UpdateUserRequestDto = {\n phoneNumber: dto.phoneNumber\n ? cleanPhoneNumber(dto.phoneNumber)\n : undefined,\n fullName: dto.fullName\n ? cleanStringAndLowercase(dto.fullName)\n : undefined,\n pushToken: dto.pushToken ? cleanString(dto.pushToken) : undefined,\n tz: dto.tz ? utcOffsetToHours(dto.tz) : undefined,\n };\n\n const user: User = await this.userService.update(\n req.user.userId,\n cleanDto,\n );\n\n if (user.fullName && user.phoneNumber) {\n await this.userService.update(req.user.userId, {\n onboardingStatus: OnboardingStatus.COMPLETED,\n });\n }\n\n return user as GetUserResponseDto;\n } catch (error) {\n handleError(error);\n }\n }\n\n @UseGuards(AuthGuard)\n @Post('pushTest')\n @ApiResponse({\n status: 200,\n description: 'push test successful',\n })\n async pushTest(@Request() req): Promise<void> {\n try {\n const user: User = await this.userService.findOneByUserId(\n req.user.userId,\n );\n\n if (user.pushToken) {\n const messages: ExpoPushMessage[] = this.pushService.createMessages({\n body: 'Test push',\n pushTokens: [user.pushToken],\n });\n await this.pushService.sendMessages(messages);\n }\n } catch (error) {\n handleError(error);\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC"}
|
package/dist/cjs/utils/index.js
CHANGED
|
@@ -5,4 +5,5 @@ tslib_1.__exportStar(require("./datetime.util"), exports);
|
|
|
5
5
|
tslib_1.__exportStar(require("./error.util"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./input.util"), exports);
|
|
7
7
|
tslib_1.__exportStar(require("./string.util"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./noop.util"), exports);
|
|
8
9
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["utils/index.ts"],"names":[],"mappings":";;;AAAA,0DAAgC;AAChC,uDAA6B;AAC7B,uDAA6B;AAC7B,wDAA8B","sourcesContent":["export * from './datetime.util';\nexport * from './error.util';\nexport * from './input.util';\nexport * from './string.util';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["utils/index.ts"],"names":[],"mappings":";;;AAAA,0DAAgC;AAChC,uDAA6B;AAC7B,uDAA6B;AAC7B,wDAA8B;AAC9B,sDAA4B","sourcesContent":["export * from './datetime.util';\nexport * from './error.util';\nexport * from './input.util';\nexport * from './string.util';\nexport * from './noop.util';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"noop.util.d.ts","sourceRoot":"/","sources":["utils/noop.util.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"noop.util.d.ts","sourceRoot":"/","sources":["utils/noop.util.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI,YAAW,CAAC;AAC7B,eAAO,MAAM,SAAS,qBAAiB,CAAC"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
5
|
-
exports.
|
|
3
|
+
exports.noopAsync = exports.noop = void 0;
|
|
4
|
+
const noop = () => { };
|
|
5
|
+
exports.noop = noop;
|
|
6
|
+
const noopAsync = async () => { };
|
|
7
|
+
exports.noopAsync = noopAsync;
|
|
6
8
|
//# sourceMappingURL=noop.util.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"noop.util.js","sourceRoot":"/","sources":["utils/noop.util.ts"],"names":[],"mappings":";;;AAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"noop.util.js","sourceRoot":"/","sources":["utils/noop.util.ts"],"names":[],"mappings":";;;AAAO,MAAM,IAAI,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;AAAhB,QAAA,IAAI,QAAY;AACtB,MAAM,SAAS,GAAG,KAAK,IAAI,EAAE,GAAE,CAAC,CAAC;AAA3B,QAAA,SAAS,aAAkB","sourcesContent":["export const noop = () => {};\nexport const noopAsync = async () => {};\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as stytch from 'stytch';
|
|
1
2
|
import { ConfigService } from '@nestjs/config';
|
|
2
3
|
import { RegisterRequestDto } from '../user/dtos/register.request.dto';
|
|
3
4
|
export declare class AuthService {
|
|
@@ -5,7 +6,8 @@ export declare class AuthService {
|
|
|
5
6
|
private readonly logger;
|
|
6
7
|
private authClient;
|
|
7
8
|
constructor(configService: ConfigService);
|
|
8
|
-
signup(data: RegisterRequestDto): Promise<
|
|
9
|
+
signup(data: RegisterRequestDto): Promise<stytch.PasswordsCreateResponse>;
|
|
9
10
|
login(data: RegisterRequestDto): Promise<boolean>;
|
|
11
|
+
delete(externalId: string): Promise<void>;
|
|
10
12
|
}
|
|
11
13
|
//# sourceMappingURL=auth.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.service.d.ts","sourceRoot":"/","sources":["auth/auth.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"auth.service.d.ts","sourceRoot":"/","sources":["auth/auth.service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAC;AAGvE,qBACa,WAAW;IAIV,OAAO,CAAC,aAAa;IAHjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAwC;IAC/D,OAAO,CAAC,UAAU,CAAgB;gBAEd,aAAa,EAAE,aAAa;IAW1C,MAAM,CACV,IAAI,EAAE,kBAAkB,GACvB,OAAO,CAAC,MAAM,CAAC,uBAAuB,CAAC;IASpC,KAAK,CAAC,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,OAAO,CAAC;IAiBjD,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAKhD"}
|
|
@@ -19,7 +19,7 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
19
19
|
async signup(data) {
|
|
20
20
|
this.logger.debug('signup');
|
|
21
21
|
const res = await this.authClient.passwords.create(data);
|
|
22
|
-
return res
|
|
22
|
+
return res;
|
|
23
23
|
}
|
|
24
24
|
async login(data) {
|
|
25
25
|
this.logger.debug('login');
|
|
@@ -36,6 +36,10 @@ let AuthService = AuthService_1 = class AuthService {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
+
async delete(externalId) {
|
|
40
|
+
this.logger.debug('delete');
|
|
41
|
+
await this.authClient.users.delete({ user_id: externalId });
|
|
42
|
+
}
|
|
39
43
|
};
|
|
40
44
|
AuthService = AuthService_1 = __decorate([
|
|
41
45
|
Injectable(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.service.js","sourceRoot":"/","sources":["auth/auth.service.ts"],"names":[],"mappings":";;AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAG/C,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAGhC,IAAM,WAAW,mBAAjB,MAAM,WAAW;IAItB,YAAoB,aAA4B;QAA5B,kBAAa,GAAb,aAAa,CAAe;QAH/B,WAAM,GAAW,IAAI,MAAM,CAAC,aAAW,CAAC,IAAI,CAAC,CAAC;QAI7D,IAAI,CAAC,UAAU,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC;YAClC,UAAU,EAAE,IAAI,CAAC,aAAa,CAAC,GAAG,CAAS,mBAAmB,CAAC;YAC/D,MAAM,EAAE,IAAI,CAAC,aAAa,CAAC,GAAG,CAAS,eAAe,CAAC;YACvD,GAAG,EACD,IAAI,CAAC,aAAa,CAAC,GAAG,CAAS,YAAY,CAAC,KAAK,MAAM;gBACrD,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI;gBAClB,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI;SACvB,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,MAAM,
|
|
1
|
+
{"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S,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;YAC/D,OAAO,GAAG,CAAC,aAAa,CAAC,KAAK,GAAG,CAAC;QACpC,CAAC;QAAC,OAAO,KAAU,EAAE,CAAC;YACpB,IAAI,KAAK,CAAC,UAAU,KAAK,iBAAiB,EAAE,CAAC;gBAC3C,WAAW,CAAC,4BAA4B,CAAC,CAAC;YAC5C,CAAC;YAED,IAAI,KAAK,CAAC,UAAU,KAAK,0BAA0B,EAAE,CAAC;gBACpD,WAAW,CAAC,4BAA4B,CAAC,CAAC;YAC5C,CAAC;QACH,CAAC;IACH,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,UAAkB;QAC7B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAE5B,MAAM,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC,CAAC;IAC9D,CAAC;CACF,CAAA;AAhDY,WAAW;IADvB,UAAU,EAAE;qCAKwB,aAAa;GAJrC,WAAW,CAgDvB","sourcesContent":["import { Injectable, Logger } from '@nestjs/common';\nimport * as stytch from 'stytch';\nimport { ConfigService } from '@nestjs/config';\n\nimport { RegisterRequestDto } from '../user/dtos/register.request.dto';\nimport { handleError } from '../utils';\n\n@Injectable()\nexport class AuthService {\n private readonly logger: Logger = new Logger(AuthService.name);\n private authClient: stytch.Client;\n\n constructor(private configService: ConfigService) {\n this.authClient = new stytch.Client({\n project_id: this.configService.get<string>('STYTCH_PROJECT_ID'),\n secret: this.configService.get<string>('STYTCH_SECRET'),\n env:\n this.configService.get<string>('STYTCH_ENV') === 'test'\n ? stytch.envs.test\n : stytch.envs.live,\n });\n }\n\n async signup(\n data: RegisterRequestDto,\n ): Promise<stytch.PasswordsCreateResponse> {\n this.logger.debug('signup');\n\n const res: stytch.PasswordsCreateResponse =\n await this.authClient.passwords.create(data);\n\n return res;\n }\n\n async login(data: RegisterRequestDto): Promise<boolean> {\n this.logger.debug('login');\n\n try {\n const res = await this.authClient.passwords.authenticate(data);\n return res['status_code'] === 200;\n } catch (error: any) {\n if (error.error_type === 'email_not_found') {\n handleError('Email or password is wrong');\n }\n\n if (error.error_type === 'unauthorized_credentials') {\n handleError('Email or password is wrong');\n }\n }\n }\n\n async delete(externalId: string): Promise<void> {\n this.logger.debug('delete');\n\n await this.authClient.users.delete({ user_id: externalId });\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete-user.request.dto.d.ts","sourceRoot":"/","sources":["user/dtos/delete-user.request.dto.ts"],"names":[],"mappings":"AAGA,qBAAa,oBAAoB;IAG/B,KAAK,EAAE,MAAM,CAAC;CACf"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { IsString } from 'class-validator';
|
|
3
|
+
import { ApiProperty } from '@nestjs/swagger';
|
|
4
|
+
export class DeleteUserRequestDto {
|
|
5
|
+
}
|
|
6
|
+
__decorate([
|
|
7
|
+
IsString(),
|
|
8
|
+
ApiProperty(),
|
|
9
|
+
__metadata("design:type", String)
|
|
10
|
+
], DeleteUserRequestDto.prototype, "email", void 0);
|
|
11
|
+
//# sourceMappingURL=delete-user.request.dto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete-user.request.dto.js","sourceRoot":"/","sources":["user/dtos/delete-user.request.dto.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,MAAM,OAAO,oBAAoB;CAIhC;AADC;IAFC,QAAQ,EAAE;IACV,WAAW,EAAE;;mDACA","sourcesContent":["import { IsString } from 'class-validator';\nimport { ApiProperty } from '@nestjs/swagger';\n\nexport class DeleteUserRequestDto {\n @IsString()\n @ApiProperty()\n email: string;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["user/dtos/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["user/dtos/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["user/dtos/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC","sourcesContent":["export * from './get-user.response.dto';\nexport * from './register.request.dto';\nexport * from './register.response.dto';\nexport * from './update-user.request.dto';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["user/dtos/index.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC","sourcesContent":["export * from './get-user.response.dto';\nexport * from './register.request.dto';\nexport * from './register.response.dto';\nexport * from './update-user.request.dto';\nexport * from './delete-user.request.dto';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.controller.d.ts","sourceRoot":"/","sources":["user/user.controller.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"user.controller.d.ts","sourceRoot":"/","sources":["user/user.controller.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAMzC,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAUnD,qBAEa,cAAc;IAEvB,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,UAAU;gBAHV,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,WAAW,EACxB,WAAW,EAAE,WAAW,EACxB,UAAU,EAAE,UAAU;IAS1B,MAAM,CAAS,GAAG,EAAE,kBAAkB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAqCrE,KAAK,CAAS,GAAG,EAAE,kBAAkB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAkCpE,OAAO,CAAY,GAAG,KAAA,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAmBpD,IAAI,CACA,GAAG,EAAE,oBAAoB,EACtB,GAAG,KAAA,GACb,OAAO,CAAC,kBAAkB,CAAC;IAoCxB,QAAQ,CAAY,GAAG,KAAA,GAAG,OAAO,CAAC,IAAI,CAAC;CAiB9C"}
|
|
@@ -24,22 +24,13 @@ let UserController = class UserController {
|
|
|
24
24
|
email: cleanStringAndLowercase(dto.email),
|
|
25
25
|
password: cleanString(dto.password),
|
|
26
26
|
};
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
handleError('Error creating user');
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
catch (error) {
|
|
34
|
-
if (error === null || error === void 0 ? void 0 : error.error_message) {
|
|
35
|
-
handleError(error.error_message);
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
handleError('Error creating user');
|
|
39
|
-
}
|
|
27
|
+
const res = await this.authService.signup(cleanedDTO);
|
|
28
|
+
if (!res) {
|
|
29
|
+
handleError('Error creating user');
|
|
40
30
|
}
|
|
41
31
|
const user = await this.userService.create({
|
|
42
32
|
email: cleanedDTO.email,
|
|
33
|
+
externalId: res.user_id,
|
|
43
34
|
});
|
|
44
35
|
if (!user) {
|
|
45
36
|
handleError('Error creating user');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user.controller.js","sourceRoot":"/","sources":["user/user.controller.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,IAAI,EACJ,UAAU,EACV,GAAG,EACH,IAAI,EACJ,OAAO,EACP,SAAS,GACV,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAQ,MAAM,gBAAgB,CAAC;AAGxD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EACL,gBAAgB,EAChB,WAAW,EACX,uBAAuB,EACvB,WAAW,EACX,gBAAgB,GACjB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,SAAS,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AAE,sBAAsB;KACpC,CAAC;IACc,WAAA,OAAO,EAAE,CAAA;;;;8CAgBxB;AArKU,cAAc;IAF1B,OAAO,CAAC,MAAM,CAAC;IACf,UAAU,CAAC,MAAM,CAAC;qCAGM,WAAW;QACX,WAAW;QACX,WAAW;QACZ,UAAU;GALrB,cAAc,CAsK1B","sourcesContent":["import {\n Body,\n Controller,\n Get,\n Post,\n Request,\n UseGuards,\n} from '@nestjs/common';\nimport { JwtService } from '@nestjs/jwt';\nimport { ApiResponse, ApiTags } from '@nestjs/swagger';\nimport { OnboardingStatus, User } from '@prisma/client';\nimport { ExpoPushMessage } from 'expo-server-sdk';\n\nimport { AuthService } from '../auth/auth.service';\nimport { UserService } from './user.service';\nimport { GetUserResponseDto } from './dtos/get-user.response.dto';\nimport { UpdateUserRequestDto } from './dtos/update-user.request.dto';\nimport { RegisterResponseDto } from './dtos/register.response.dto';\nimport { RegisterRequestDto } from './dtos/register.request.dto';\nimport { PushService } from '../push/push.service';\nimport {\n cleanPhoneNumber,\n cleanString,\n cleanStringAndLowercase,\n handleError,\n utcOffsetToHours,\n} from '../utils';\nimport { AuthGuard } from '../guard';\n\n@ApiTags('User')\n@Controller('user')\nexport class UserController {\n constructor(\n private userService: UserService,\n private authService: AuthService,\n private pushService: PushService,\n private jwtService: JwtService,\n ) {}\n\n @Post('signup')\n @ApiResponse({\n status: 200,\n description: 'loginOrCreate successful',\n type: RegisterResponseDto,\n })\n async signup(@Body() dto: RegisterRequestDto): Promise<RegisterResponseDto> {\n const cleanedDTO: RegisterRequestDto = {\n email: cleanStringAndLowercase(dto.email),\n password: cleanString(dto.password),\n };\n\n try {\n const res: boolean = await this.authService.signup(cleanedDTO);\n\n if (!res) {\n handleError('Error creating user');\n }\n } catch (error: any) {\n if (error?.error_message) {\n handleError(error.error_message);\n } else {\n handleError('Error creating user');\n }\n }\n\n const user: User = await this.userService.create({\n email: cleanedDTO.email,\n });\n\n if (!user) {\n handleError('Error creating user');\n }\n\n const payload = { userId: user.id };\n const token: string = await this.jwtService.signAsync(payload);\n\n return {\n ...user,\n token,\n };\n }\n\n @Post('login')\n @ApiResponse({\n status: 200,\n description: 'loginOrCreate successful',\n type: RegisterResponseDto,\n })\n async login(@Body() dto: RegisterRequestDto): Promise<RegisterResponseDto> {\n const cleanedDTO: RegisterRequestDto = {\n email: cleanStringAndLowercase(dto.email),\n password: dto.password.trim(),\n };\n\n const res: boolean = await this.authService.login(cleanedDTO);\n\n if (!res) {\n handleError('Error logging in');\n }\n\n const user: User = await this.userService.findOneByEmail(cleanedDTO.email);\n\n if (!user) {\n handleError('Error logging in');\n }\n\n const payload = { userId: user.id };\n const token: string = await this.jwtService.signAsync(payload);\n\n return {\n ...user,\n token,\n };\n }\n\n @UseGuards(AuthGuard)\n @Get('self')\n @ApiResponse({\n status: 200,\n description: 'get self successful',\n type: GetUserResponseDto,\n })\n async getSelf(@Request() req): Promise<GetUserResponseDto> {\n try {\n const user: User = await this.userService.findOneByUserId(\n req.user.userId,\n );\n\n return user as GetUserResponseDto;\n } catch (error) {\n handleError(error);\n }\n }\n\n @UseGuards(AuthGuard)\n @Post('update')\n @ApiResponse({\n status: 200,\n description: 'update user successful',\n type: GetUserResponseDto,\n })\n async edit(\n @Body() dto: UpdateUserRequestDto,\n @Request() req,\n ): Promise<GetUserResponseDto> {\n try {\n const cleanDto: UpdateUserRequestDto = {\n phoneNumber: dto.phoneNumber\n ? cleanPhoneNumber(dto.phoneNumber)\n : undefined,\n fullName: dto.fullName\n ? cleanStringAndLowercase(dto.fullName)\n : undefined,\n pushToken: dto.pushToken ? cleanString(dto.pushToken) : undefined,\n tz: dto.tz ? utcOffsetToHours(dto.tz) : undefined,\n };\n\n const user: User = await this.userService.update(\n req.user.userId,\n cleanDto,\n );\n\n if (user.fullName && user.phoneNumber) {\n await this.userService.update(req.user.userId, {\n onboardingStatus: OnboardingStatus.COMPLETED,\n });\n }\n\n return user as GetUserResponseDto;\n } catch (error) {\n handleError(error);\n }\n }\n\n @UseGuards(AuthGuard)\n @Post('pushTest')\n @ApiResponse({\n status: 200,\n description: 'push test successful',\n })\n async pushTest(@Request() req): Promise<void> {\n try {\n const user: User = await this.userService.findOneByUserId(\n req.user.userId,\n );\n\n if (user.pushToken) {\n const messages: ExpoPushMessage[] = this.pushService.createMessages({\n body: 'Test push',\n pushTokens: [user.pushToken],\n });\n await this.pushService.sendMessages(messages);\n }\n } catch (error) {\n handleError(error);\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"user.controller.js","sourceRoot":"/","sources":["user/user.controller.ts"],"names":[],"mappings":";AAAA,OAAO,EACL,IAAI,EACJ,UAAU,EACV,GAAG,EACH,IAAI,EACJ,OAAO,EACP,SAAS,GACV,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAQ,MAAM,gBAAgB,CAAC;AAIxD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EACL,gBAAgB,EAChB,WAAW,EACX,uBAAuB,EACvB,WAAW,EACX,gBAAgB,GACjB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAI9B,IAAM,cAAc,GAApB,MAAM,cAAc;IACzB,YACU,WAAwB,EACxB,WAAwB,EACxB,WAAwB,EACxB,UAA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EAAE,0BAA0B;QACvC,IAAI,EAAE,mBAAmB;KAC1B,CAAC;IACY,WAAA,IAAI,EAAE,CAAA;;qCAAM,kBAAkB;;4CA6B3C;AAQK;IANL,IAAI,CAAC,OAAO,CAAC;IACb,WAAW,CAAC;QACX,MAAM,EAAE,GAAG;QACX,WAAW,EAAE,0BAA0B;QACvC,IAAI,EAAE,mBAAmB;KAC1B,CAAC;IACW,WAAA,IAAI,EAAE,CAAA;;qCAAM,kBAAkB;;2CAyB1C;AASK;IAPL,SAAS,CAAC,SAAS,CAAC;IACpB,GAAG,CAAC,MAAM,CAAC;IACX,WAAW,CAAC;QACX,MAAM,EAAE,GAAG;QACX,WAAW,EAAE,qBAAqB;QAClC,IAAI,EAAE,kBAAkB;KACzB,CAAC;IACa,WAAA,OAAO,EAAE,CAAA;;;;6CAUvB;AASK;IAPL,SAAS,CAAC,SAAS,CAAC;IACpB,IAAI,CAAC,QAAQ,CAAC;IACd,WAAW,CAAC;QACX,MAAM,EAAE,GAAG;QACX,WAAW,EAAE,wBAAwB;QACrC,IAAI,EAAE,kBAAkB;KACzB,CAAC;IAEC,WAAA,IAAI,EAAE,CAAA;IACN,WAAA,OAAO,EAAE,CAAA;;qCADG,oBAAoB;;0CA8BlC;AAQK;IANL,SAAS,CAAC,SAAS,CAAC;IACpB,IAAI,CAAC,UAAU,CAAC;IAChB,WAAW,CAAC;QACX,MAAM,EAAE,GAAG;QACX,WAAW,EAAE,sBAAsB;KACpC,CAAC;IACc,WAAA,OAAO,EAAE,CAAA;;;;8CAgBxB;AA/JU,cAAc;IAF1B,OAAO,CAAC,MAAM,CAAC;IACf,UAAU,CAAC,MAAM,CAAC;qCAGM,WAAW;QACX,WAAW;QACX,WAAW;QACZ,UAAU;GALrB,cAAc,CAgK1B","sourcesContent":["import {\n Body,\n Controller,\n Get,\n Post,\n Request,\n UseGuards,\n} from '@nestjs/common';\nimport { JwtService } from '@nestjs/jwt';\nimport { ApiResponse, ApiTags } from '@nestjs/swagger';\nimport { OnboardingStatus, User } from '@prisma/client';\nimport { ExpoPushMessage } from 'expo-server-sdk';\nimport * as stytch from 'stytch';\n\nimport { AuthService } from '../auth/auth.service';\nimport { UserService } from './user.service';\nimport { GetUserResponseDto } from './dtos/get-user.response.dto';\nimport { UpdateUserRequestDto } from './dtos/update-user.request.dto';\nimport { RegisterResponseDto } from './dtos/register.response.dto';\nimport { RegisterRequestDto } from './dtos/register.request.dto';\nimport { PushService } from '../push/push.service';\nimport {\n cleanPhoneNumber,\n cleanString,\n cleanStringAndLowercase,\n handleError,\n utcOffsetToHours,\n} from '../utils';\nimport { AuthGuard } from '../guard';\n\n@ApiTags('User')\n@Controller('user')\nexport class UserController {\n constructor(\n private userService: UserService,\n private authService: AuthService,\n private pushService: PushService,\n private jwtService: JwtService,\n ) {}\n\n @Post('signup')\n @ApiResponse({\n status: 200,\n description: 'loginOrCreate successful',\n type: RegisterResponseDto,\n })\n async signup(@Body() dto: RegisterRequestDto): Promise<RegisterResponseDto> {\n const cleanedDTO: RegisterRequestDto = {\n email: cleanStringAndLowercase(dto.email),\n password: cleanString(dto.password),\n };\n\n const res: stytch.PasswordsCreateResponse =\n await this.authService.signup(cleanedDTO);\n\n if (!res) {\n handleError('Error creating user');\n }\n\n const user: User = await this.userService.create({\n email: cleanedDTO.email,\n externalId: res.user_id,\n });\n\n if (!user) {\n handleError('Error creating user');\n }\n\n const payload = { userId: user.id };\n const token: string = await this.jwtService.signAsync(payload);\n\n return {\n ...user,\n token,\n };\n }\n\n @Post('login')\n @ApiResponse({\n status: 200,\n description: 'loginOrCreate successful',\n type: RegisterResponseDto,\n })\n async login(@Body() dto: RegisterRequestDto): Promise<RegisterResponseDto> {\n const cleanedDTO: RegisterRequestDto = {\n email: cleanStringAndLowercase(dto.email),\n password: dto.password.trim(),\n };\n\n const res: boolean = await this.authService.login(cleanedDTO);\n\n if (!res) {\n handleError('Error logging in');\n }\n\n const user: User = await this.userService.findOneByEmail(cleanedDTO.email);\n\n if (!user) {\n handleError('Error logging in');\n }\n\n const payload = { userId: user.id };\n const token: string = await this.jwtService.signAsync(payload);\n\n return {\n ...user,\n token,\n };\n }\n\n @UseGuards(AuthGuard)\n @Get('self')\n @ApiResponse({\n status: 200,\n description: 'get self successful',\n type: GetUserResponseDto,\n })\n async getSelf(@Request() req): Promise<GetUserResponseDto> {\n try {\n const user: User = await this.userService.findOneByUserId(\n req.user.userId,\n );\n\n return user as GetUserResponseDto;\n } catch (error) {\n handleError(error);\n }\n }\n\n @UseGuards(AuthGuard)\n @Post('update')\n @ApiResponse({\n status: 200,\n description: 'update user successful',\n type: GetUserResponseDto,\n })\n async edit(\n @Body() dto: UpdateUserRequestDto,\n @Request() req,\n ): Promise<GetUserResponseDto> {\n try {\n const cleanDto: UpdateUserRequestDto = {\n phoneNumber: dto.phoneNumber\n ? cleanPhoneNumber(dto.phoneNumber)\n : undefined,\n fullName: dto.fullName\n ? cleanStringAndLowercase(dto.fullName)\n : undefined,\n pushToken: dto.pushToken ? cleanString(dto.pushToken) : undefined,\n tz: dto.tz ? utcOffsetToHours(dto.tz) : undefined,\n };\n\n const user: User = await this.userService.update(\n req.user.userId,\n cleanDto,\n );\n\n if (user.fullName && user.phoneNumber) {\n await this.userService.update(req.user.userId, {\n onboardingStatus: OnboardingStatus.COMPLETED,\n });\n }\n\n return user as GetUserResponseDto;\n } catch (error) {\n handleError(error);\n }\n }\n\n @UseGuards(AuthGuard)\n @Post('pushTest')\n @ApiResponse({\n status: 200,\n description: 'push test successful',\n })\n async pushTest(@Request() req): Promise<void> {\n try {\n const user: User = await this.userService.findOneByUserId(\n req.user.userId,\n );\n\n if (user.pushToken) {\n const messages: ExpoPushMessage[] = this.pushService.createMessages({\n body: 'Test push',\n pushTokens: [user.pushToken],\n });\n await this.pushService.sendMessages(messages);\n }\n } catch (error) {\n handleError(error);\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"/","sources":["utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC"}
|
package/dist/esm/utils/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"/","sources":["utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC","sourcesContent":["export * from './datetime.util';\nexport * from './error.util';\nexport * from './input.util';\nexport * from './string.util';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC","sourcesContent":["export * from './datetime.util';\nexport * from './error.util';\nexport * from './input.util';\nexport * from './string.util';\nexport * from './noop.util';\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"noop.util.d.ts","sourceRoot":"/","sources":["utils/noop.util.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"noop.util.d.ts","sourceRoot":"/","sources":["utils/noop.util.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI,YAAW,CAAC;AAC7B,eAAO,MAAM,SAAS,qBAAiB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"noop.util.js","sourceRoot":"/","sources":["utils/noop.util.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,
|
|
1
|
+
{"version":3,"file":"noop.util.js","sourceRoot":"/","sources":["utils/noop.util.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,IAAI,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;AAC7B,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,IAAI,EAAE,GAAE,CAAC,CAAC","sourcesContent":["export const noop = () => {};\nexport const noopAsync = async () => {};\n"]}
|