All files / src/lambda lambdaIdentity.ts

100% Statements 43/43
100% Branches 0/0
100% Functions 11/11
100% Lines 43/43

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143  4x                         4x 4x 4x           4x   4x   1x 1x         4x   1x 1x           4x   1x 1x         4x   1x 1x         4x         1x 1x 1x 1x 1x         4x   1x 1x                     4x   1x 1x           4x   1x 1x                     4x   1x 1x                     4x         1x 1x 1x         4x   1x 1x 1x        
import { Handler, Context } from 'aws-lambda';
import {
  withMiddlewares,
  bootstrapNestJSMiddleware,
  types,
} from '@npco/component-core';
import {
  IdentitySignUpInput,
  IdentityLoginInput,
  CheckAccessTokenInput,
  PhoneRegisterInput,
  PhoneVerifyInput,
  PinInput,
} from '../types.d';
import { IdentityService } from '../identity/service/identityService';
import { AppModule } from '../appModule';
import {
  logMiddleware,
  accessTokenMiddleware,
  validateDeviceTokenMiddleware,
  checkDeviceStatusMiddleware,
} from '../middlewares';
import { ChangePasswordInputDto } from '../identity/dtos/identityDto';
 
export const identitySignUp: Handler = withMiddlewares(
  (event: { args: { input: IdentitySignUpInput } }, context: Context) => {
    const app = (context as types.AppContext).app;
    return app.get(IdentityService).identitySignUp(event.args.input);
  },
  [bootstrapNestJSMiddleware(AppModule), logMiddleware],
);
 
export const identityLogin: Handler = withMiddlewares(
  (event: { args: { input: IdentityLoginInput } }, context: Context) => {
    const app = (context as types.AppContext).app;
    return app.get(IdentityService).identityLogin(event.args.input);
  },
 
  [bootstrapNestJSMiddleware(AppModule), logMiddleware],
);
 
export const checkAccessToken: Handler = withMiddlewares(
  (event: { args: { input: CheckAccessTokenInput } }, context: Context) => {
    const app = (context as types.AppContext).app;
    return app.get(IdentityService).checkAccessToken(event.args.input);
  },
  [bootstrapNestJSMiddleware(AppModule), logMiddleware],
);
 
export const identityForgotPassword: Handler = withMiddlewares(
  (event: { args: { email: string } }, context: Context) => {
    const app = (context as types.AppContext).app;
    return app.get(IdentityService).identityForgotPassword(event.args.email);
  },
  [bootstrapNestJSMiddleware(AppModule), logMiddleware],
);
 
export const identityChangePassword: Handler = withMiddlewares(
  (
    event: { args: { password: string }; identity: { sub: string } },
    context: Context,
  ) => {
    const app = (context as types.AppContext).app;
    const userId = event.identity.sub;
    const password = event.args.password;
    const input = new ChangePasswordInputDto(password, userId);
    return app.get(IdentityService).identityChangePassword(input);
  },
  [bootstrapNestJSMiddleware(AppModule), logMiddleware],
);
 
export const identityPhoneRegister: Handler = withMiddlewares(
  (event: { args: PhoneRegisterInput }, context: Context) => {
    const app = (context as types.AppContext).app;
    return app.get(IdentityService).identityPhoneRegister(event.args);
  },
  [
    bootstrapNestJSMiddleware(AppModule),
    accessTokenMiddleware,
    validateDeviceTokenMiddleware,
    checkDeviceStatusMiddleware,
    logMiddleware,
  ],
);
 
export const identityPhoneVerify: Handler = withMiddlewares(
  (event: { args: PhoneVerifyInput }, context: Context) => {
    const app = (context as types.AppContext).app;
    return app.get(IdentityService).identityPhoneVerify(event.args);
  },
  [bootstrapNestJSMiddleware(AppModule), accessTokenMiddleware, checkDeviceStatusMiddleware,
    logMiddleware],
);
 
export const identitySetPin: Handler = withMiddlewares(
  (event: { args: PinInput; accessToken: string }, context: Context) => {
    const app = (context as types.AppContext).app;
    return app.get(IdentityService).identitySetPin(event.args);
  },
  [
    bootstrapNestJSMiddleware(AppModule),
    accessTokenMiddleware,
    validateDeviceTokenMiddleware,
    checkDeviceStatusMiddleware,
    logMiddleware,
  ],
);
 
export const identityVerifyPin: Handler = withMiddlewares(
  (event: { args: PinInput; accessToken: string }, context: Context) => {
    const app = (context as types.AppContext).app;
    return app.get(IdentityService).identityVerifyPin(event.args);
  },
  [
    bootstrapNestJSMiddleware(AppModule),
    accessTokenMiddleware,
    validateDeviceTokenMiddleware,
    checkDeviceStatusMiddleware,
    logMiddleware,
  ],
);
 
export const identityForcedLogoff: Handler = withMiddlewares(
  (
    event: { args: { deviceUuid: string; reason: string } },
    context: Context,
  ) => {
    const app = (context as types.AppContext).app;
    const { deviceUuid, reason } = event.args;
    return app.get(IdentityService).identityForcedLogoff(deviceUuid, reason);
  },
  [bootstrapNestJSMiddleware(AppModule), logMiddleware],
);
 
export const initiateForcedLogoff: Handler = withMiddlewares(
  (event: any, context: Context) => {
    const app = (context as types.AppContext).app;
    const { deviceUuid, reason } = event.args;
    return app.get(IdentityService).initiateForcedLogoff(deviceUuid, reason);
  },
  [bootstrapNestJSMiddleware(AppModule), logMiddleware],
);