File tree Expand file tree Collapse file tree 7 files changed +61
-43
lines changed
migrations/20241003153039_add_license_key Expand file tree Collapse file tree 7 files changed +61
-43
lines changed Original file line number Diff line number Diff line change 1
- FROM node:18-alpine AS dependences
2
- WORKDIR /app
3
-
4
- COPY package.json yarn.lock ./
5
- RUN yarn install --production --frozen-lockfile
1
+ # Use the official Node.js image as the base image
2
+ FROM node:18-alpine
6
3
7
- FROM node:18-alpine AS builder
4
+ # Set the working directory inside the container
8
5
WORKDIR /app
9
6
10
- COPY package.json yarn.lock ./
11
- RUN yarn --frozen-lockfile
12
-
13
- COPY . .
7
+ # Copy package.json and package-lock.json to the working directory
8
+ COPY package*.json ./
14
9
15
- RUN yarn build
10
+ # Install dependencies
11
+ RUN npm install
16
12
17
- FROM node:18-alpine AS runner
18
- WORKDIR /app
19
-
20
- ARG NODE_ENV=production
21
- ENV NODE_ENV=${NODE_ENV}
13
+ # Copy the rest of the application code to the working directory
14
+ COPY . .
22
15
23
- COPY --from=dependences /app/node_modules ./node_modules
24
- COPY --from=builder /app/dist ./dist
16
+ # Build the NestJS application
17
+ RUN npm run build
25
18
19
+ # Expose the port your NestJS application listens on
26
20
EXPOSE 8080
27
21
28
- CMD ["node" , "dist/main" ]
22
+ # Define the command to run your NestJS application
23
+ CMD ["node" , "--max-old-space-size=4096" , "dist/main.js" ]
Original file line number Diff line number Diff line change @@ -74,3 +74,6 @@ Nest is [MIT licensed](LICENSE).
74
74
75
75
## Prisma Initialize
76
76
- This project source use prisma as ORM, so to start prisma use this command: ` yarn prisma init `
77
+
78
+ ## Run docker with .env file
79
+ -` docker run -d --name nestjs-backend --env-file .env -p 8080:8080 gateway-server `
Original file line number Diff line number Diff line change 1
- version : " 23.0.5"
2
- services :
3
- dev-db :
4
- image : postgres:13
1
+ version : " 3.8"
2
+ services :
3
+ backend :
4
+ container_name : graphql-server
5
+ mem_limit : 2g
6
+ restart : always
7
+ build :
8
+ dockerfile : Dockerfile
5
9
ports :
6
- # map the contianer port: 5432 to localhost port 5430
7
- - 5430:5432
10
+ - " 8080:8080"
8
11
environment :
9
- POSTGRES_USER : root
10
- POSTGRES_PASSWORD : dtth2802
11
- POSTGRES_DB : nest
12
- networks :
13
- - postgres-network
14
- test-db :
15
- image : postgres:13
16
- ports :
17
- # map the contianer port: 5432 to localhost port 5430
18
- - 5433:5435
19
- environment :
20
- POSTGRES_USER : root
21
- POSTGRES_PASSWORD : dtth2802
22
- POSTGRES_DB : nest
23
- networks :
24
- - postgres-network
12
+ - DB_HOST=localhost
13
+ - DB_PORT=3306
14
+ - DB_USER=thuhuong
15
+ - DB_PASSWORD=thuhuong0208
16
+ - DB_NAME=gatewaydb
17
+
25
18
networks :
26
- postgres-network:
19
+ mysql-network :
20
+ driver : bridge
21
+
Original file line number Diff line number Diff line change
1
+ -- AlterTable
2
+ ALTER TABLE ` user` ADD COLUMN ` hub_license_key` VARCHAR (100 ) NULL ;
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ model user {
19
19
username String ? @unique @db.VarChar (100 )
20
20
password String ? @db.VarChar (100 )
21
21
22
+ hub_license_key String ? @db.VarChar (100 )
22
23
token_cache_login String ? @db.VarChar (100 )
23
24
session session []
24
25
device device []
Original file line number Diff line number Diff line change 1
- import { Resolver , Query } from "@nestjs/graphql" ;
1
+ import { Resolver , Query , Args } from "@nestjs/graphql" ;
2
2
import { UseGuards } from "@nestjs/common" ;
3
3
4
4
import { UserService } from "./user.service" ;
@@ -16,4 +16,10 @@ export class UserResolver {
16
16
const user = this . userService . findOne ( Number ( session . session . userId ) ) ;
17
17
return user ;
18
18
}
19
+
20
+ @Query ( ( ) => User )
21
+ userByLicense ( @Args ( "license" ) license : string ) {
22
+ const user = this . userService . findUserByLicense ( license ) ;
23
+ return user ;
24
+ }
19
25
}
Original file line number Diff line number Diff line change @@ -39,4 +39,20 @@ export class UserService {
39
39
throw error ;
40
40
}
41
41
}
42
+
43
+ async findUserByLicense ( license : string ) {
44
+ try {
45
+ const user = await this . prisma . user . findFirst ( {
46
+ where : {
47
+ hub_license_key : license
48
+ }
49
+ } ) ;
50
+ if ( ! user ) {
51
+ throw new NotFoundException ( "User not found" ) ;
52
+ }
53
+ return user ;
54
+ } catch ( error ) {
55
+ throw error ;
56
+ }
57
+ }
42
58
}
You can’t perform that action at this time.
0 commit comments