Trần Viết Sơn commited on
Commit
3d3ad65
2 Parent(s): 2b0b6de 8b7e5fc

Merge pull request #2 from PBL6-team-CATS/feat/backend/branch-and-menu

Browse files
backend/.env.example CHANGED
@@ -1,5 +1,5 @@
1
- DB_HOST=0.0.0.0
2
- DB_PORT=3306
3
- DB_USER='root'
4
- DB_PASSWORD='your_password'
5
- DB_NAME='pbl6'
 
1
+ DB_HOST=dpg-cs6i9ll6l47c73ffheh0-a
2
+ DB_PORT=5432
3
+ DB_USER='pbl6_jw8s_user'
4
+ DB_PASSWORD=''
5
+ DB_NAME='pbl6_jw8s'
backend/Dockerfile ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use an official Node.js runtime as a parent image
2
+ FROM node:22-alpine
3
+
4
+ # Set the working directory
5
+ WORKDIR /app
6
+
7
+ # Copy package.json and package-lock.json
8
+ COPY package*.json ./
9
+
10
+ # Install dependencies
11
+ RUN npm install
12
+
13
+ # Copy the rest of the application code
14
+ COPY . .
15
+
16
+ # Build the application
17
+ RUN npm run build
18
+
19
+
20
+ COPY entrypoint.sh ./entrypoint.sh
21
+
22
+ # Expose the port that the app will run on
23
+ EXPOSE 3000
24
+
25
+ # Command to run the application
26
+ ENTRYPOINT ["./entrypoint.sh"]
27
+ CMD ["npm", "run", "start:prod"]
backend/README.md CHANGED
@@ -17,7 +17,7 @@ $ npm install
17
 
18
  #### 3. Create .env file
19
 
20
- - Copy from `.env.example`
21
 
22
  ## Compile and run the project
23
 
@@ -29,6 +29,21 @@ $ npm run start
29
  $ npm run start:dev
30
  ```
31
 
32
- ## Run tests
33
 
34
- We currently don't care about test
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
  #### 3. Create .env file
19
 
20
+ - Copy from `.env.example` and fill
21
 
22
  ## Compile and run the project
23
 
 
29
  $ npm run start:dev
30
  ```
31
 
32
+ ## In product:
33
 
34
+ ## Notice
35
+
36
+ ```bash
37
+ # generate migrations
38
+ $ npm run db:migrate:generate src/migrations/NameOfMigrations
39
+
40
+ # update database follow migrations
41
+ $ npm run db:migrate:up
42
+
43
+ # down database follow migrations
44
+ $ npm run db:migrate:down
45
+
46
+ # Generate resource (include module, controller, service) and moving them to modules
47
+ $ npx nest g resource modules/<resource_name>
48
+
49
+ ```
backend/entrypoint.sh ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ #!/bin/sh
2
+
3
+ npm run db:migrate:up
4
+
5
+ # Start the application using the command passed as arguments to this script
6
+ exec "$@"
7
+
backend/package-lock.json CHANGED
@@ -12,6 +12,7 @@
12
  "@nestjs/common": "^10.0.0",
13
  "@nestjs/config": "^3.2.3",
14
  "@nestjs/core": "^10.0.0",
 
15
  "@nestjs/platform-express": "^10.0.0",
16
  "@nestjs/typeorm": "^10.0.2",
17
  "dotenv": "^16.4.5",
@@ -1690,6 +1691,26 @@
1690
  }
1691
  }
1692
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1693
  "node_modules/@nestjs/platform-express": {
1694
  "version": "10.4.3",
1695
  "resolved": "https://registry.npmjs.org/@nestjs/platform-express/-/platform-express-10.4.3.tgz",
 
12
  "@nestjs/common": "^10.0.0",
13
  "@nestjs/config": "^3.2.3",
14
  "@nestjs/core": "^10.0.0",
15
+ "@nestjs/mapped-types": "*",
16
  "@nestjs/platform-express": "^10.0.0",
17
  "@nestjs/typeorm": "^10.0.2",
18
  "dotenv": "^16.4.5",
 
1691
  }
1692
  }
1693
  },
1694
+ "node_modules/@nestjs/mapped-types": {
1695
+ "version": "2.0.5",
1696
+ "resolved": "https://registry.npmjs.org/@nestjs/mapped-types/-/mapped-types-2.0.5.tgz",
1697
+ "integrity": "sha512-bSJv4pd6EY99NX9CjBIyn4TVDoSit82DUZlL4I3bqNfy5Gt+gXTa86i3I/i0iIV9P4hntcGM5GyO+FhZAhxtyg==",
1698
+ "license": "MIT",
1699
+ "peerDependencies": {
1700
+ "@nestjs/common": "^8.0.0 || ^9.0.0 || ^10.0.0",
1701
+ "class-transformer": "^0.4.0 || ^0.5.0",
1702
+ "class-validator": "^0.13.0 || ^0.14.0",
1703
+ "reflect-metadata": "^0.1.12 || ^0.2.0"
1704
+ },
1705
+ "peerDependenciesMeta": {
1706
+ "class-transformer": {
1707
+ "optional": true
1708
+ },
1709
+ "class-validator": {
1710
+ "optional": true
1711
+ }
1712
+ }
1713
+ },
1714
  "node_modules/@nestjs/platform-express": {
1715
  "version": "10.4.3",
1716
  "resolved": "https://registry.npmjs.org/@nestjs/platform-express/-/platform-express-10.4.3.tgz",
backend/package.json CHANGED
@@ -28,6 +28,7 @@
28
  "@nestjs/common": "^10.0.0",
29
  "@nestjs/config": "^3.2.3",
30
  "@nestjs/core": "^10.0.0",
 
31
  "@nestjs/platform-express": "^10.0.0",
32
  "@nestjs/typeorm": "^10.0.2",
33
  "dotenv": "^16.4.5",
 
28
  "@nestjs/common": "^10.0.0",
29
  "@nestjs/config": "^3.2.3",
30
  "@nestjs/core": "^10.0.0",
31
+ "@nestjs/mapped-types": "*",
32
  "@nestjs/platform-express": "^10.0.0",
33
  "@nestjs/typeorm": "^10.0.2",
34
  "dotenv": "^16.4.5",
backend/src/app.module.ts CHANGED
@@ -8,6 +8,7 @@ import { DatabaseConfigService } from './config/database.js';
8
  import { AppLoggerMiddleware } from './common/middlewares/app-logger.middleware.js';
9
  import { DeviceInfoMiddleware } from './common/middlewares/device-info.middleware.js';
10
  import { UserModule } from './modules/user/user.module.js';
 
11
 
12
  @Module({
13
  imports: [
@@ -20,6 +21,7 @@ import { UserModule } from './modules/user/user.module.js';
20
  useClass: DatabaseConfigService,
21
  }),
22
  UserModule,
 
23
  ],
24
  controllers: [AppController],
25
  providers: [AppService],
 
8
  import { AppLoggerMiddleware } from './common/middlewares/app-logger.middleware.js';
9
  import { DeviceInfoMiddleware } from './common/middlewares/device-info.middleware.js';
10
  import { UserModule } from './modules/user/user.module.js';
11
+ import { BranchModule } from './modules/branch/branch.module.js';
12
 
13
  @Module({
14
  imports: [
 
21
  useClass: DatabaseConfigService,
22
  }),
23
  UserModule,
24
+ BranchModule,
25
  ],
26
  controllers: [AppController],
27
  providers: [AppService],
backend/src/modules/branch/branch.controller.ts ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import {
2
+ Controller,
3
+ Get,
4
+ Post,
5
+ Body,
6
+ Patch,
7
+ Param,
8
+ Delete,
9
+ } from '@nestjs/common';
10
+ import { BranchService } from './branch.service.js';
11
+ import { BranchDto } from './dto/create-branch.dto.js';
12
+
13
+ @Controller('branch')
14
+ export class BranchController {
15
+ constructor(private readonly branchService: BranchService) {}
16
+
17
+ @Post()
18
+ create(@Body() createBranchDto: BranchDto) {
19
+ return this.branchService.create(createBranchDto);
20
+ }
21
+
22
+ @Get()
23
+ findAll() {
24
+ return this.branchService.findAll();
25
+ }
26
+
27
+ @Get(':id')
28
+ findOne(@Param('id') id: string) {
29
+ return this.branchService.findOne(+id);
30
+ }
31
+
32
+ @Patch(':id')
33
+ update(@Param('id') id: string, @Body() updateBranchDto: BranchDto) {
34
+ return this.branchService.update(+id, updateBranchDto);
35
+ }
36
+
37
+ @Delete(':id')
38
+ remove(@Param('id') id: string) {
39
+ return this.branchService.remove(+id);
40
+ }
41
+ }
backend/src/modules/branch/branch.module.ts ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import { Module } from '@nestjs/common';
2
+ import { BranchService } from './branch.service.js';
3
+ import { BranchController } from './branch.controller.js';
4
+
5
+ @Module({
6
+ controllers: [BranchController],
7
+ providers: [BranchService],
8
+ })
9
+ export class BranchModule {}
backend/src/modules/branch/branch.service.ts ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { Injectable } from '@nestjs/common';
2
+ import { BranchDto } from './dto/create-branch.dto';
3
+
4
+ @Injectable()
5
+ export class BranchService {
6
+ create(createBranchDto: BranchDto) {
7
+ return 'This action adds a new branch';
8
+ }
9
+
10
+ findAll() {
11
+ return `This action returns all branch`;
12
+ }
13
+
14
+ findOne(id: number) {
15
+ return `This action returns a #${id} branch`;
16
+ }
17
+
18
+ update(id: number, updateBranchDto: BranchDto) {
19
+ return `This action updates a #${id} branch`;
20
+ }
21
+
22
+ remove(id: number) {
23
+ return `This action removes a #${id} branch`;
24
+ }
25
+ }
backend/src/modules/branch/dto/create-branch.dto.ts ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ export interface BranchDto {
2
+ id: string;
3
+ name: string;
4
+ location: string;
5
+ phone_number: string;
6
+ owner_id: string;
7
+ }