Skip to content

Commit

Permalink
Merge pull request #500 from andrechristikan/development
Browse files Browse the repository at this point in the history
JSON stringify cause issue for reseponse and response paging serializ…
  • Loading branch information
andrechristikan committed Dec 12, 2023
2 parents d8e7c17 + d1575cd commit 6c68afc
Show file tree
Hide file tree
Showing 12 changed files with 214 additions and 157 deletions.
95 changes: 92 additions & 3 deletions .github/workflows/cd.yml → .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
name: CD

name: CI_CD
on:
# push:
# branches:
Expand All @@ -8,7 +7,97 @@ on:
workflow_dispatch:

jobs:
build_image:
runs-on: ubuntu-latest

env:
DOCKER_HUB: ${{ secrets.DOCKER_HUB }}
DOCKERFILE: ci/dockerfile

steps:
- name: Git checkout
uses: actions/checkout@v3

- name: Get git short sha
id: git
run: |
echo "short_sha=$(git rev-parse --short $GITHUB_SHA)" >> "$GITHUB_OUTPUT"
- name: Get latest version of package json
id: version
uses: martinbeentjes/npm-get-version-action@main

- name: Git
run: |
echo Short sha: ${{ steps.git.outputs.short_sha }}
echo Version is: ${{ steps.version.outputs.current-version }}
- name: Environment
run: |
echo DOCKER_HUB is: ${{ env.DOCKER_HUB }}
echo DOCKERFILE is: ${{ env.DOCKERFILE }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

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

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

- name: Builder name
run: echo ${{ steps.builder.outputs.name }}

- name: Main name
run: echo ${{ steps.main.outputs.name }}

- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build builder
uses: docker/build-push-action@v4
with:
builder: ${{ steps.builder.outputs.name }}
file: ${{ env.DOCKERFILE }}
target: builder

- name: Build main and push
uses: docker/build-push-action@v4
if: ${{ github.ref_name == 'main' }}
with:
builder: ${{ steps.main.outputs.name }}
file: ${{ env.DOCKERFILE }}
build-args: |
NODE_ENV=production
target: main
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.DOCKER_HUB }}:latest
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.DOCKER_HUB }}:main_v${{ steps.version.outputs.current-version }}
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.DOCKER_HUB }}:main_v${{ steps.version.outputs.current-version }}_sha-${{ steps.git.outputs.short_sha }}
push: true

- name: Build staging and push
uses: docker/build-push-action@v4
if: ${{ github.ref_name == 'staging' }}
with:
builder: ${{ steps.main.outputs.name }}
file: ${{ env.DOCKERFILE }}
build-args: |
NODE_ENV=staging
target: main
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.DOCKER_HUB }}:staging_v${{ steps.version.outputs.current-version }}
${{ secrets.DOCKERHUB_USERNAME }}/${{ env.DOCKER_HUB }}:staging_v${{ steps.version.outputs.current-version }}_sha-${{ steps.git.outputs.short_sha }}
push: true

deploy_production:
needs: [ build_image ]
runs-on: ubuntu-latest
if: ${{ github.ref_name == 'main' }}
environment: production
Expand Down Expand Up @@ -91,8 +180,8 @@ jobs:
user: ${{ env.SSH_USER }}
key: ${{ env.SSH_PRIVATE_KEY }}


deploy_staging:
needs: [ build_image ]
runs-on: ubuntu-latest
if: ${{ github.ref_name == 'staging' }}
environment: staging
Expand Down
97 changes: 0 additions & 97 deletions .github/workflows/ci.yml

This file was deleted.

1 change: 1 addition & 0 deletions src/common/api-key/controllers/api-key.admin.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export class ApiKeyAdminController {
offset: _offset,
},
order: _order,
plainObject: true,
});
const total: number = await this.apiKeyService.getTotal(find);
const totalPage: number = this.paginationService.totalPage(
Expand Down
4 changes: 2 additions & 2 deletions src/common/dashboard/constants/dashboard.doc.constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const DashboardDocQueryStartDate = [
allowEmptyValue: true,
required: false,
type: 'string',
example: faker.date.recent().toString(),
example: faker.date.past(),
},
];

Expand All @@ -16,6 +16,6 @@ export const DashboardDocQueryEndDate = [
allowEmptyValue: true,
required: false,
type: 'string',
example: faker.date.recent().toString(),
example: faker.date.recent(),
},
];
32 changes: 18 additions & 14 deletions src/common/dashboard/services/dashboard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,27 @@ export class DashboardService implements IDashboardService {
getStartAndEndDate(date?: DashboardDto): IDashboardStartAndEndDate {
const today = this.helperDateService.create();

if (!date) {
const startDate = this.helperDateService.startOfMonth(today);
const endDate = this.helperDateService.endOfMonth(today);

return {
startDate,
endDate,
};
}
let { startDate, endDate } = date;

if (!startDate && !endDate) {
startDate = this.helperDateService.startOfYear(today);
endDate = this.helperDateService.endOfYear(today);
if (!startDate) {
startDate = this.helperDateService.startOfMonth();
} else {
startDate = this.helperDateService.startOfDay(startDate);
}

if (!endDate) {
endDate = this.helperDateService.endOfMonth();
} else {
if (!startDate) {
startDate = this.helperDateService.startOfYear();
} else {
startDate = this.helperDateService.startOfDay(startDate);
}

if (!endDate) {
endDate = this.helperDateService.endOfYear();
} else {
endDate = this.helperDateService.endOfDay(endDate);
}
endDate = this.helperDateService.endOfDay(endDate);
}

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,7 @@ export class ResponseDefaultInterceptor<T>

if (responseData) {
const { _metadata } = responseData;
data = responseData.data
? JSON.parse(
JSON.stringify(responseData.data ?? {})
)
: undefined;
data = responseData.data;

if (data && classSerialization) {
data = plainToInstance(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@ export class ResponsePagingInterceptor<T>
}

const { _metadata } = responseData;
data = responseData.data
? JSON.parse(JSON.stringify(responseData.data ?? {}))
: undefined;
data = responseData.data;

if (classSerialization) {
data = plainToInstance(
Expand Down
1 change: 1 addition & 0 deletions src/modules/role/controllers/role.admin.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export class RoleAdminController {
offset: _offset,
},
order: _order,
plainObject: true,
});

const total: number = await this.roleService.getTotal(find);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export class SettingPublicController {
offset: _offset,
},
order: _order,
plainObject: true,
}
);
const total: number = await this.settingService.getTotal(find);
Expand Down
10 changes: 8 additions & 2 deletions src/modules/user/controllers/user.admin.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ export class UserAdminController {
offset: _offset,
},
order: _order,
plainObject: true,
});
const total: number = await this.userService.getTotal(find);
const totalPage: number = this.paginationService.totalPage(
Expand Down Expand Up @@ -186,7 +187,7 @@ export class UserAdminController {
async get(@GetUser() user: UserDoc): Promise<IResponse> {
const userWithRole: IUserDoc =
await this.userService.joinWithRole(user);
return { data: userWithRole };
return { data: userWithRole.toObject() };
}

@UserAdminCreateDoc()
Expand Down Expand Up @@ -398,7 +399,12 @@ export class UserAdminController {
@HttpCode(HttpStatus.OK)
@Post('/export')
async export(): Promise<IResponse> {
const users: IUserEntity[] = await this.userService.findAll({});
const users: IUserEntity[] = await this.userService.findAll(
{},
{
plainObject: true,
}
);

return { data: users };
}
Expand Down
2 changes: 1 addition & 1 deletion src/modules/user/controllers/user.auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ export class UserAuthController {
async profile(@GetUser() user: UserDoc): Promise<IResponse> {
const userWithRole: IUserDoc =
await this.userService.joinWithRole(user);
return { data: userWithRole };
return { data: userWithRole.toObject() };
}

@UserAuthUpdateProfileDoc()
Expand Down
Loading

0 comments on commit 6c68afc

Please sign in to comment.