Skip to content

Commit

Permalink
Merge pull request #516 from andrechristikan/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
andrechristikan authored Jun 16, 2024
2 parents 7413b24 + 9bbdee6 commit d727a86
Show file tree
Hide file tree
Showing 119 changed files with 4,688 additions and 2,596 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ URL_VERSION=1

JOB_ENABLE=false

DATABASE_URI=mongodb://admin@password:localhost:30001,localhost:30002,localhost:30003/ack?replicaSet=rs0&retryWrites=true&w=majority
DATABASE_URI=mongodb://admin:password@localhost:30001,localhost:30002,localhost:30003/ack?replicaSet=rs0&retryWrites=true&w=majority
DATABASE_DEBUG=false

AUTH_JWT_SUBJECT=AckDevelopment
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ permissions:
on:

workflow_dispatch:
push:
branches:
- main

jobs:
release:
Expand Down
4 changes: 2 additions & 2 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM node:lts-alpine
LABEL maintainer "[email protected]"
LABEL maintainer "[email protected]"

ENV NODE_ENV=${NODE_ENV}

Expand All @@ -10,7 +10,7 @@ COPY package.json yarn.lock ./
RUN touch .env

RUN mkdir data
RUN set -x && yarn
RUN set -x && yarn --frozen-lockfile

COPY . .

Expand Down
10 changes: 10 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ docker-compose up -d

This project need to do migration for running. [Read this][ack-database-migration-doc]

## Email Migration

The email will automatically create email template through AWS SES

For migrate
```bash
yarn migrate:email
```



[ack-database-migration-doc]: /docs/database_migration.md

Expand Down
49 changes: 25 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "ack-nestjs-boilerplate",
"version": "6.0.1",
"version": "6.1.0",
"description": "Ack NestJs Boilerplate",
"repository": {
"type": "git",
"url": "https://github.com/andrechristikan/ack-nestjs-boilerplate.git"
},
"author": {
"name": "andrechristikan",
"email": "[email protected]"
"email": "[email protected]"
},
"private": true,
"license": "MIT",
Expand All @@ -27,39 +27,40 @@
"deadcode": "ts-prune --project tsconfig.json --unusedInModule --skip *.json",
"spell": "cspell lint --config cspell.json '{src,test}/**/*.ts' --color --gitignore --no-must-find-files --no-summary --no-progress || true",
"upgrade:package": "ncu -u",
"seed": "nestjs-command seed:email && nestjs-command seed:setting && nestjs-command seed:apikey && nestjs-command seed:role && nestjs-command seed:user",
"rollback": "nestjs-command remove:email && nestjs-command remove:setting && nestjs-command remove:apikey && nestjs-command remove:user && nestjs-command remove:role"
"migrate:email": "nestjs-command migrate:email",
"seed": "nestjs-command seed:country && nestjs-command seed:apikey && nestjs-command seed:role && nestjs-command seed:user",
"rollback": "nestjs-command remove:country && nestjs-command remove:apikey && nestjs-command remove:user && nestjs-command remove:role"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.583.0",
"@aws-sdk/client-ses": "^3.583.0",
"@aws-sdk/client-s3": "^3.598.0",
"@aws-sdk/client-ses": "^3.598.0",
"@casl/ability": "^6.7.1",
"@faker-js/faker": "^8.4.1",
"@nestjs/axios": "^3.0.2",
"@nestjs/common": "^10.3.8",
"@nestjs/common": "^10.3.9",
"@nestjs/config": "^3.2.2",
"@nestjs/core": "^10.3.8",
"@nestjs/core": "^10.3.9",
"@nestjs/jwt": "^10.2.0",
"@nestjs/mongoose": "^10.0.6",
"@nestjs/passport": "^10.0.3",
"@nestjs/platform-express": "^10.3.8",
"@nestjs/platform-express": "^10.3.9",
"@nestjs/schedule": "^4.0.2",
"@nestjs/swagger": "^7.3.1",
"@nestjs/terminus": "^10.2.3",
"@nestjs/throttler": "^5.1.2",
"@nestjs/throttler": "^5.2.0",
"@ntegral/nestjs-sentry": "^4.0.1",
"@sentry/node": "^8.4.0",
"@sentry/node": "^8.9.2",
"axios": "^1.7.2",
"bcryptjs": "^2.4.3",
"case": "^1.6.3",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"crypto-js": "^4.2.0",
"google-auth-library": "^9.10.0",
"google-auth-library": "^9.11.0",
"helmet": "^7.1.0",
"moment": "^2.30.1",
"moment-timezone": "^0.5.45",
"mongoose": "^8.4.0",
"mongoose": "^8.4.1",
"nestjs-command": "^3.1.4",
"nestjs-i18n": "^10.4.5",
"passport": "^0.7.0",
Expand All @@ -76,10 +77,10 @@
"devDependencies": {
"@commitlint/cli": "^19.3.0",
"@commitlint/config-conventional": "^19.2.2",
"@eslint/js": "^9.3.0",
"@eslint/js": "^9.5.0",
"@nestjs/cli": "^10.3.2",
"@nestjs/schematics": "^10.1.1",
"@nestjs/testing": "^10.3.8",
"@nestjs/testing": "^10.3.9",
"@types/bcryptjs": "^2.4.6",
"@types/bytes": "^3.1.4",
"@types/cors": "^2.8.17",
Expand All @@ -88,29 +89,29 @@
"@types/eslint__js": "^8.42.3",
"@types/express": "^4.17.21",
"@types/jest": "^29.5.12",
"@types/lodash": "^4.17.4",
"@types/lodash": "^4.17.5",
"@types/ms": "^0.7.34",
"@types/multer": "^1.4.11",
"@types/node": "^20.12.12",
"@types/node": "^20.14.2",
"@types/passport-jwt": "^4.0.1",
"@types/response-time": "^2.3.8",
"@types/supertest": "^6.0.2",
"@types/uuid": "^9.0.8",
"cspell": "^8.8.3",
"eslint": "^9.3.0",
"cspell": "^8.8.4",
"eslint": "^9.5.0",
"eslint-config-prettier": "^9.1.0",
"husky": "^9.0.11",
"jest": "^29.7.0",
"lint-staged": "^15.2.4",
"prettier": "^3.2.5",
"stop-only": "^3.3.1",
"lint-staged": "^15.2.7",
"prettier": "^3.3.2",
"stop-only": "^3.3.2",
"supertest": "^7.0.0",
"ts-jest": "^29.1.3",
"ts-jest": "^29.1.5",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"ts-prune": "^0.10.3",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.4.5",
"typescript-eslint": "^7.10.0"
"typescript-eslint": "^7.13.0"
}
}
4 changes: 0 additions & 4 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Logger } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { CommandModule, CommandService } from 'nestjs-command';
import { MigrationModule } from 'src/migration/migration.module';
Expand All @@ -8,13 +7,10 @@ async function bootstrap() {
logger: ['error'],
});

const logger = new Logger();

try {
await app.select(CommandModule).get(CommandService).exec();
process.exit(0);
} catch (err: unknown) {
logger.error(err, 'Migration');
process.exit(1);
}
}
Expand Down
32 changes: 17 additions & 15 deletions src/common/api-key/repository/entities/api-key.entity.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
import { Prop, SchemaFactory } from '@nestjs/mongoose';
import { Document } from 'mongoose';
import { DatabaseMongoUUIDEntityAbstract } from 'src/common/database/abstracts/mongo/entities/database.mongo.uuid.entity.abstract';
import { DatabaseEntity } from 'src/common/database/decorators/database.decorator';
import {
DatabaseEntity,
DatabaseProp,
DatabaseSchema,
} from 'src/common/database/decorators/database.decorator';
import { ENUM_API_KEY_TYPE } from 'src/common/api-key/constants/api-key.enum.constant';
import { IDatabaseDocument } from 'src/common/database/interfaces/database.interface';

export const ApiKeyDatabaseName = 'apikeys';
export const ApiKeyTableName = 'ApiKeys';

@DatabaseEntity({ collection: ApiKeyDatabaseName })
@DatabaseEntity({ collection: ApiKeyTableName })
export class ApiKeyEntity extends DatabaseMongoUUIDEntityAbstract {
@Prop({
@DatabaseProp({
required: true,
enum: ENUM_API_KEY_TYPE,
index: true,
trim: true,
})
type: ENUM_API_KEY_TYPE;

@Prop({
@DatabaseProp({
required: true,
index: true,
type: String,
Expand All @@ -27,7 +30,7 @@ export class ApiKeyEntity extends DatabaseMongoUUIDEntityAbstract {
})
name: string;

@Prop({
@DatabaseProp({
required: true,
type: String,
unique: true,
Expand All @@ -37,33 +40,32 @@ export class ApiKeyEntity extends DatabaseMongoUUIDEntityAbstract {
})
key: string;

@Prop({
@DatabaseProp({
required: true,
trim: true,
type: String,
})
hash: string;

@Prop({
@DatabaseProp({
required: true,
index: true,
type: Boolean,
})
isActive: boolean;

@Prop({
@DatabaseProp({
required: false,
type: Date,
})
startDate?: Date;

@Prop({
@DatabaseProp({
required: false,
type: Date,
})
endDate?: Date;
}

export const ApiKeySchema = SchemaFactory.createForClass(ApiKeyEntity);

export type ApiKeyDoc = ApiKeyEntity & Document<string>;
export const ApiKeySchema = DatabaseSchema(ApiKeyEntity);
export type ApiKeyDoc = IDatabaseDocument<ApiKeyEntity>;
8 changes: 4 additions & 4 deletions src/common/auth/constants/auth.status-code.constant.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export enum ENUM_AUTH_STATUS_CODE_ERROR {
AUTH_JWT_ACCESS_TOKEN_ERROR = 5000,
AUTH_JWT_REFRESH_TOKEN_ERROR = 5001,
AUTH_SOCIAL_GOOGLE_ERROR = 5002,
AUTH_SOCIAL_APPLE_ERROR = 5003,
JWT_ACCESS_TOKEN_ERROR = 5000,
JWT_REFRESH_TOKEN_ERROR = 5001,
SOCIAL_GOOGLE_ERROR = 5002,
SOCIAL_APPLE_ERROR = 5003,
}
3 changes: 1 addition & 2 deletions src/common/auth/guards/jwt/auth.jwt.access.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ export class AuthJwtAccessGuard extends AuthGuard('jwtAccess') {
handleRequest<TUser = any>(err: Error, user: TUser, info: Error): TUser {
if (err || !user) {
throw new UnauthorizedException({
statusCode:
ENUM_AUTH_STATUS_CODE_ERROR.AUTH_JWT_ACCESS_TOKEN_ERROR,
statusCode: ENUM_AUTH_STATUS_CODE_ERROR.JWT_ACCESS_TOKEN_ERROR,
message: 'auth.error.accessTokenUnauthorized',
_error: err ? err.message : info.message,
});
Expand Down
3 changes: 1 addition & 2 deletions src/common/auth/guards/jwt/auth.jwt.refresh.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ export class AuthJwtRefreshGuard extends AuthGuard('jwtRefresh') {
handleRequest<TUser = any>(err: Error, user: TUser, info: Error): TUser {
if (err || !user) {
throw new UnauthorizedException({
statusCode:
ENUM_AUTH_STATUS_CODE_ERROR.AUTH_JWT_REFRESH_TOKEN_ERROR,
statusCode: ENUM_AUTH_STATUS_CODE_ERROR.JWT_REFRESH_TOKEN_ERROR,
message: 'auth.error.refreshTokenUnauthorized',
_error: err ? err.message : info.message,
});
Expand Down
6 changes: 2 additions & 4 deletions src/common/auth/guards/social/auth.social.apple.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ export class AuthSocialAppleGuard implements CanActivate {

if (acArr.length !== 2) {
throw new UnauthorizedException({
statusCode:
ENUM_AUTH_STATUS_CODE_ERROR.AUTH_SOCIAL_GOOGLE_ERROR,
statusCode: ENUM_AUTH_STATUS_CODE_ERROR.SOCIAL_GOOGLE_ERROR,
message: 'auth.error.socialApple',
});
}
Expand All @@ -41,8 +40,7 @@ export class AuthSocialAppleGuard implements CanActivate {
return true;
} catch (err: any) {
throw new UnauthorizedException({
statusCode:
ENUM_AUTH_STATUS_CODE_ERROR.AUTH_SOCIAL_GOOGLE_ERROR,
statusCode: ENUM_AUTH_STATUS_CODE_ERROR.SOCIAL_GOOGLE_ERROR,
message: 'auth.error.socialApple',
});
}
Expand Down
6 changes: 2 additions & 4 deletions src/common/auth/guards/social/auth.social.google.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ export class AuthSocialGoogleGuard implements CanActivate {
const acArr = authorization?.split('Bearer ') ?? [];
if (acArr.length !== 2) {
throw new UnauthorizedException({
statusCode:
ENUM_AUTH_STATUS_CODE_ERROR.AUTH_SOCIAL_GOOGLE_ERROR,
statusCode: ENUM_AUTH_STATUS_CODE_ERROR.SOCIAL_GOOGLE_ERROR,
message: 'auth.error.socialGoogle',
});
}
Expand All @@ -40,8 +39,7 @@ export class AuthSocialGoogleGuard implements CanActivate {
return true;
} catch (err: any) {
throw new UnauthorizedException({
statusCode:
ENUM_AUTH_STATUS_CODE_ERROR.AUTH_SOCIAL_GOOGLE_ERROR,
statusCode: ENUM_AUTH_STATUS_CODE_ERROR.SOCIAL_GOOGLE_ERROR,
message: 'auth.error.socialGoogle',
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/common/auth/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export class AuthService implements IAuthService {
}

async createPasswordRandom(): Promise<string> {
return this.helperStringService.random(15);
return this.helperStringService.random(10);
}

async checkPasswordExpired(passwordExpired: Date): Promise<boolean> {
Expand Down
8 changes: 4 additions & 4 deletions src/common/aws/dtos/aws.s3-multipart.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ApiProperty, getSchemaPath } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import { AwsS3Dto } from 'src/common/aws/dtos/aws.s3.dto';

export class AwsS3MultipartPartsDto {
export class AwsS3MultipartPartDto {
@ApiProperty({
required: true,
nullable: false,
Expand Down Expand Up @@ -63,11 +63,11 @@ export class AwsS3MultipartDto extends AwsS3Dto {
nullable: false,
oneOf: [
{
$ref: getSchemaPath(AwsS3MultipartPartsDto),
$ref: getSchemaPath(AwsS3MultipartPartDto),
type: 'array',
},
],
})
@Type(() => AwsS3MultipartPartsDto)
parts: AwsS3MultipartPartsDto[];
@Type(() => AwsS3MultipartPartDto)
parts: AwsS3MultipartPartDto[];
}
6 changes: 3 additions & 3 deletions src/common/aws/interfaces/aws.s3-service.interface.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HeadBucketCommandOutput, UploadPartRequest } from '@aws-sdk/client-s3';
import {
AwsS3MultipartDto,
AwsS3MultipartPartsDto,
AwsS3MultipartPartDto,
} from 'src/common/aws/dtos/aws.s3-multipart.dto';
import { AwsS3Dto } from 'src/common/aws/dtos/aws.s3.dto';
import {
Expand Down Expand Up @@ -43,10 +43,10 @@ export interface IAwsS3Service {
multipart: AwsS3MultipartDto,
partNumber: number,
content: UploadPartRequest['Body'] | string | Uint8Array | Buffer
): Promise<AwsS3MultipartPartsDto>;
): Promise<AwsS3MultipartPartDto>;
updateMultiPart(
{ size, parts, ...others }: AwsS3MultipartDto,
part: AwsS3MultipartPartsDto
part: AwsS3MultipartPartDto
): Promise<AwsS3MultipartDto>;
completeMultipart(multipart: AwsS3MultipartDto): Promise<void>;
abortMultipart(multipart: AwsS3MultipartDto): Promise<void>;
Expand Down
Loading

0 comments on commit d727a86

Please sign in to comment.