Skip to content

Commit

Permalink
Merge pull request #485 from andrechristikan/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
andrechristikan committed Oct 19, 2023
2 parents 3733c19 + e9d01ab commit 3e63704
Show file tree
Hide file tree
Showing 18 changed files with 327 additions and 312 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3

- name: Deploy
uses: fifsky/ssh-action@master
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ jobs:
uses: docker/setup-qemu-action@v2

- name: Set up Docker Buildx for Builder
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3
id: builder

- name: Set up Docker Buildx for Main
uses: docker/setup-buildx-action@v2
uses: docker/setup-buildx-action@v3
id: main

- name: Builder name
Expand All @@ -56,7 +56,7 @@ jobs:
run: echo ${{ steps.main.outputs.name }}

- name: Login to DockerHub
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
- [ACK NestJs Boilerplate 🔥 🚀](#ack-nestjs-boilerplate---)
- [Table of contents](#table-of-contents)
- [Important](#important)
- [Next Todo](#next-todo)
- [Todo](#todo)
- [Documentation](#documentation)
- [License](#license)
- [Contribute](#contribute)
Expand All @@ -45,12 +45,12 @@
1. CorsMiddleware will implement `src/configs/middleware.config.ts`.
2. Documentation will `disable`.

## Next Todo

Next development
## Todo

* [ ] Update Documentation, add behaviors
* [ ] Update Documentation, include an diagram for easier comprehension
* [ ] Update Documentation, and include an diagram for easier comprehension
* [ ] Add Redis
* [ ] Implement GraphQL

# Documentation

Expand Down
40 changes: 20 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"rollback": "yarn rollback:setting && yarn rollback:apikey && yarn rollback:user && yarn rollback:role"
},
"dependencies": {
"@aws-sdk/client-s3": "^3.428.0",
"@aws-sdk/client-s3": "^3.431.0",
"@casl/ability": "^6.5.0",
"@faker-js/faker": "^8.2.0",
"@joi/date": "^2.1.0",
Expand All @@ -63,7 +63,7 @@
"@nestjs/swagger": "^7.1.13",
"@nestjs/terminus": "^10.1.1",
"@nestjs/throttler": "^5.0.0",
"@types/response-time": "^2.3.6",
"@types/response-time": "^2.3.7",
"axios": "^1.5.1",
"bcryptjs": "^2.4.3",
"class-transformer": "^0.5.1",
Expand All @@ -73,7 +73,7 @@
"helmet": "^7.0.0",
"joi": "^17.11.0",
"moment": "^2.29.4",
"mongoose": "^7.6.2",
"mongoose": "^7.6.3",
"morgan": "^1.10.0",
"nest-winston": "^1.9.4",
"nestjs-command": "^3.1.4",
Expand All @@ -97,24 +97,24 @@
"@nestjs/cli": "^10.1.18",
"@nestjs/schematics": "^10.0.2",
"@nestjs/testing": "^10.2.7",
"@types/bcryptjs": "^2.4.4",
"@types/bytes": "^3.1.2",
"@types/cors": "^2.8.14",
"@types/bcryptjs": "^2.4.5",
"@types/bytes": "^3.1.3",
"@types/cors": "^2.8.15",
"@types/cron": "^2.0.1",
"@types/crypto-js": "^4.1.2",
"@types/express": "^4.17.19",
"@types/jest": "^29.5.5",
"@types/lodash": "^4.14.199",
"@types/morgan": "^1.9.6",
"@types/ms": "^0.7.32",
"@types/multer": "^1.4.8",
"@types/node": "^20.8.6",
"@types/passport-jwt": "^3.0.10",
"@types/supertest": "^2.0.14",
"@types/ua-parser-js": "^0.7.37",
"@types/uuid": "^9.0.5",
"@typescript-eslint/eslint-plugin": "^6.7.5",
"@typescript-eslint/parser": "^6.7.5",
"@types/crypto-js": "^4.1.3",
"@types/express": "^4.17.20",
"@types/jest": "^29.5.6",
"@types/lodash": "^4.14.200",
"@types/morgan": "^1.9.7",
"@types/ms": "^0.7.33",
"@types/multer": "^1.4.9",
"@types/node": "^20.8.7",
"@types/passport-jwt": "^3.0.11",
"@types/supertest": "^2.0.15",
"@types/ua-parser-js": "^0.7.38",
"@types/uuid": "^9.0.6",
"@typescript-eslint/eslint-plugin": "^6.8.0",
"@typescript-eslint/parser": "^6.8.0",
"cspell": "^7.3.8",
"eslint": "^8.51.0",
"eslint-config-prettier": "^9.0.0",
Expand Down
9 changes: 9 additions & 0 deletions src/common/api-key/docs/api-key.admin.doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export function ApiKeyAdminListDoc(): MethodDecorator {
queries: ApiKeyDocQueryIsActive,
}),
DocAuth({
apiKey: true,
jwtAccessToken: true,
}),
DocGuard({ role: true, policy: true }),
Expand All @@ -48,6 +49,7 @@ export function ApiKeyAdminGetDoc(): MethodDecorator {
params: ApiKeyDocParamsId,
}),
DocAuth({
apiKey: true,
jwtAccessToken: true,
}),
DocResponse<ApiKeyGetSerialization>('apiKey.get', {
Expand All @@ -69,6 +71,7 @@ export function ApiKeyAdminCreateDoc(): MethodDecorator {
return applyDecorators(
Doc({ summary: 'create an api key' }),
DocAuth({
apiKey: true,
jwtAccessToken: true,
}),
DocRequest({
Expand All @@ -90,6 +93,7 @@ export function ApiKeyAdminActiveDoc(): MethodDecorator {
params: ApiKeyDocParamsId,
}),
DocAuth({
apiKey: true,
jwtAccessToken: true,
}),
DocResponse('apiKey.active'),
Expand Down Expand Up @@ -125,6 +129,7 @@ export function ApiKeyAdminInactiveDoc(): MethodDecorator {
params: ApiKeyDocParamsId,
}),
DocAuth({
apiKey: true,
jwtAccessToken: true,
}),
DocResponse('apiKey.inactive'),
Expand Down Expand Up @@ -160,6 +165,7 @@ export function ApiKeyAdminResetDoc(): MethodDecorator {
params: ApiKeyDocParamsId,
}),
DocAuth({
apiKey: true,
jwtAccessToken: true,
}),
DocGuard({ role: true, policy: true }),
Expand Down Expand Up @@ -199,6 +205,7 @@ export function ApiKeyAdminUpdateDoc(): MethodDecorator {
body: ApiKeyUpdateDto,
}),
DocAuth({
apiKey: true,
jwtAccessToken: true,
}),
DocGuard({ role: true, policy: true }),
Expand Down Expand Up @@ -238,6 +245,7 @@ export function ApiKeyAdminUpdateDateDoc(): MethodDecorator {
body: ApiKeyUpdateDateDto,
}),
DocAuth({
apiKey: true,
jwtAccessToken: true,
}),
DocGuard({ role: true, policy: true }),
Expand Down Expand Up @@ -275,6 +283,7 @@ export function ApiKeyAdminDeleteDoc(): MethodDecorator {
params: ApiKeyDocParamsId,
}),
DocAuth({
apiKey: true,
jwtAccessToken: true,
}),
DocGuard({ role: true, policy: true }),
Expand Down
9 changes: 3 additions & 6 deletions src/common/api-key/dtos/api-key.update-date.dto.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ApiProperty } from '@nestjs/swagger';
import { faker } from '@faker-js/faker';
import { IsDate, IsNotEmpty } from 'class-validator';
import { Type } from 'class-transformer';
import { IsISO8601, IsNotEmpty } from 'class-validator';
import { GreaterThanEqual } from 'src/common/request/validations/request.greater-than-equal.validation';
import { DateGreaterThanEqualToday } from 'src/common/request/validations/request.date-greater-than-equal-today.validation';

Expand All @@ -13,8 +12,7 @@ export class ApiKeyUpdateDateDto {
nullable: true,
})
@IsNotEmpty()
@Type(() => Date)
@IsDate()
@IsISO8601()
@DateGreaterThanEqualToday()
startDate: Date;

Expand All @@ -25,8 +23,7 @@ export class ApiKeyUpdateDateDto {
nullable: true,
})
@IsNotEmpty()
@Type(() => Date)
@IsDate()
@IsISO8601()
@GreaterThanEqual('startDate')
endDate: Date;
}
9 changes: 7 additions & 2 deletions src/common/aws/services/aws.s3.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import {
AbortMultipartUploadCommandOutput,
Bucket,
_Object,
ObjectCannedACL,
} from '@aws-sdk/client-s3';

@Injectable()
Expand Down Expand Up @@ -183,7 +184,9 @@ export class AwsS3Service implements IAwsS3Service {
options?: IAwsS3PutItemOptions
): Promise<AwsS3Serialization> {
let path: string = options?.path;
const acl: string = options?.acl ? options.acl : 'public-read';
const acl: ObjectCannedACL = options?.acl
? (options.acl as ObjectCannedACL)
: ObjectCannedACL.public_read;

if (path)
path = path.startsWith('/') ? path.replace('/', '') : `${path}`;
Expand Down Expand Up @@ -304,7 +307,9 @@ export class AwsS3Service implements IAwsS3Service {
options?: IAwsS3PutItemOptions
): Promise<AwsS3MultipartSerialization> {
let path: string = options?.path;
const acl: string = options?.acl ? options.acl : 'public-read';
const acl: ObjectCannedACL = options?.acl
? (options.acl as ObjectCannedACL)
: ObjectCannedACL.public_read;

if (path)
path = path.startsWith('/') ? path.replace('/', '') : `${path}`;
Expand Down
9 changes: 3 additions & 6 deletions src/common/dashboard/dtos/dashboard.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ApiProperty } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import { IsDate, IsOptional, ValidateIf } from 'class-validator';
import { IsISO8601, IsOptional, ValidateIf } from 'class-validator';
import { GreaterThanEqual } from 'src/common/request/validations/request.greater-than-equal.validation';

export class DashboardDto {
Expand All @@ -9,9 +8,8 @@ export class DashboardDto {
required: false,
nullable: true,
})
@IsDate()
@IsISO8601()
@IsOptional()
@Type(() => Date)
@ValidateIf((e) => e.startDate !== '' || e.endDate !== '')
startDate?: Date;

Expand All @@ -20,10 +18,9 @@ export class DashboardDto {
required: false,
nullable: true,
})
@IsDate()
@IsISO8601()
@IsOptional()
@GreaterThanEqual('startDate')
@Type(() => Date)
@ValidateIf((e) => e.startDate !== '' || e.endDate !== '')
endDate?: Date;
}
12 changes: 5 additions & 7 deletions src/common/helper/services/helper.string.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,14 @@ export class HelperStringService implements IHelperStringService {
}

censor(value: string): string {
value = value.replaceAll(' ', '');
const length = value.length;
if (length <= 3) {
const stringCensor = '*'.repeat(8);
if (value.length <= 5) {
return value;
} else if (value.length <= 10) {
return `${stringCensor}${value.slice(-5)}`;
}

const end = Math.ceil(length * 0.7);
const censorString = '*'.repeat(end > 10 ? 10 : end);
const visibleString = value.substring(end, length);
return `${censorString}${visibleString}`;
return `${value.slice(0, 3)}${stringCensor}${value.slice(-5)}`;
}

checkPasswordWeak(password: string, length?: number): boolean {
Expand Down
2 changes: 2 additions & 0 deletions src/common/message/controllers/message.public.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Controller, Get, VERSION_NEUTRAL } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { ApiKeyPublicProtected } from 'src/common/api-key/decorators/api-key.decorator';
import { MessagePublicLanguageDoc } from 'src/common/message/docs/message.public.doc';
import { MessageLanguageSerialization } from 'src/common/message/serializations/message.language.serialization';
import { MessageService } from 'src/common/message/services/message.service';
Expand All @@ -18,6 +19,7 @@ export class MessagePublicController {
@Response('message.languages', {
serialization: MessageLanguageSerialization,
})
@ApiKeyPublicProtected()
@Get('/languages')
async languages(): Promise<IResponse> {
const languages: string[] = this.messageService.getAvailableLanguages();
Expand Down
7 changes: 6 additions & 1 deletion src/common/message/docs/message.public.doc.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { applyDecorators } from '@nestjs/common';
import { Doc, DocResponse } from 'src/common/doc/decorators/doc.decorator';
import {
Doc,
DocAuth,
DocResponse,
} from 'src/common/doc/decorators/doc.decorator';
import { MessageLanguageSerialization } from 'src/common/message/serializations/message.language.serialization';

export function MessagePublicLanguageDoc(): MethodDecorator {
return applyDecorators(
Doc({ summary: 'get all language of app' }),
DocAuth({ apiKey: true }),
DocResponse<MessageLanguageSerialization>('apiKey.languages', {
serialization: MessageLanguageSerialization,
})
Expand Down
2 changes: 2 additions & 0 deletions src/common/setting/controllers/setting.admin.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { BadRequestException, Body, Controller, Put } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { ApiKeyPublicProtected } from 'src/common/api-key/decorators/api-key.decorator';
import { AuthJwtAdminAccessProtected } from 'src/common/auth/decorators/auth.jwt.decorator';
import {
ENUM_POLICY_ACTION,
Expand Down Expand Up @@ -37,6 +38,7 @@ export class SettingAdminController {
action: [ENUM_POLICY_ACTION.READ, ENUM_POLICY_ACTION.UPDATE],
})
@AuthJwtAdminAccessProtected()
@ApiKeyPublicProtected()
@RequestParamGuard(SettingRequestDto)
@Put('/update/:setting')
async update(
Expand Down
3 changes: 3 additions & 0 deletions src/common/setting/controllers/setting.public.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Controller, Get } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { ApiKeyPublicProtected } from 'src/common/api-key/decorators/api-key.decorator';
import { PaginationQuery } from 'src/common/pagination/decorators/pagination.decorator';
import { PaginationListDto } from 'src/common/pagination/dtos/pagination.list.dto';
import { PaginationService } from 'src/common/pagination/services/pagination.service';
Expand Down Expand Up @@ -46,6 +47,7 @@ export class SettingPublicController {
@ResponsePaging('setting.list', {
serialization: SettingListSerialization,
})
@ApiKeyPublicProtected()
@Get('/list')
async list(
@PaginationQuery(
Expand Down Expand Up @@ -88,6 +90,7 @@ export class SettingPublicController {
serialization: SettingGetSerialization,
})
@SettingPublicGetGuard()
@ApiKeyPublicProtected()
@RequestParamGuard(SettingRequestDto)
@Get('get/:setting')
async get(@GetSetting(true) setting: SettingEntity): Promise<IResponse> {
Expand Down
1 change: 1 addition & 0 deletions src/common/setting/docs/setting.admin.doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export function SettingAdminUpdateDoc(): MethodDecorator {
}),
DocAuth({
jwtAccessToken: true,
apiKey: true,
}),
DocResponse<ResponseIdSerialization>('setting.update', {
serialization: ResponseIdSerialization,
Expand Down
Loading

0 comments on commit 3e63704

Please sign in to comment.