diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..4ecd32d1f --- /dev/null +++ b/.dockerignore @@ -0,0 +1,47 @@ +.dockerignore +README.md +LICENSE +**/docker-compose* +**/Dockerfile* + +#Git +!**/.gitignore +!.git/HEAD +!.git/config +!.git/packed-refs +!.git/refs/heads/** +**/.git +**/.gitignore + +# compiled output +/dist +/node_modules + +# Logs +logs +*.log +npm-debug.log* + +# OS +.DS_Store + +# Tests +/coverage +/.nyc_output + +# IDEs and editors +/.idea +.project +**/.vscode +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json + +#Lint +.eslintrc.js +.prettierrc + +npm-debug.log +.env* \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..f2759c9c8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,27 @@ +FROM node:20-alpine AS dev +WORKDIR /app +COPY --chown=node:node package*.json ./ +RUN npm ci +COPY --chown=node:node . . +USER node + +FROM node:20-alpine AS build +WORKDIR /app +COPY --chown=node:node package*.json ./ +COPY --chown=node:node --from=dev /app/node_modules ./node_modules +COPY --chown=node:node . . +RUN npm run build + +ENV NODE_ENV=prod +RUN npm ci --only=prod && npm cache clean --force + +USER node + +FROM node:20-alpine AS prod +WORKDIR /app +COPY --chown=node:node --from=build /app/node_modules ./node_modules +COPY --chown=node:node --from=build /app/dist ./dist + +EXPOSE 4000 + +CMD [ "node", "dist/main.js" ] \ No newline at end of file diff --git a/README.md b/README.md index a59ef9241..3713671f0 100644 --- a/README.md +++ b/README.md @@ -73,3 +73,24 @@ Nest is an MIT-licensed open source project. It can grow thanks to the sponsors ## License Nest is [MIT licensed](LICENSE). + +## Python +```bash +$ pip install virtualenv +$ pip --version +$ python -m pip install --upgrade pip +``` + +## Docker +```bash +$ docker build -t cart-service . +$ docker run -d -p 4000:4000 --name cart-service-container cart-service:latest +$ docker exec -it cart-service-container sh +$ docker images +``` + +## Eb +```bash +$ eb init +$ eb create --cname tati-moon-cart-api-dev --single +``` \ No newline at end of file diff --git a/compose-dev.yaml b/compose-dev.yaml new file mode 100644 index 000000000..0df3dae2f --- /dev/null +++ b/compose-dev.yaml @@ -0,0 +1,7 @@ +version: '3.8' + +services: + cart: + build: . + ports: + - "80:4000" \ No newline at end of file diff --git a/src/cart/models/index.ts b/src/cart/models/index.ts index 3e095c3f9..e0a4fc288 100644 --- a/src/cart/models/index.ts +++ b/src/cart/models/index.ts @@ -1,4 +1,4 @@ -enum CartStatuses { +export enum CartStatuses { OPEN = 'OPEN', STATUS = 'STATUS' } diff --git a/src/cart/services/cart.service.ts b/src/cart/services/cart.service.ts index 03c241eff..2aea3352c 100644 --- a/src/cart/services/cart.service.ts +++ b/src/cart/services/cart.service.ts @@ -1,25 +1,28 @@ import { Injectable } from '@nestjs/common'; - import { v4 } from 'uuid'; - -import { Cart } from '../models'; +import { Cart, CartStatuses } from '../models'; @Injectable() export class CartService { private userCarts: Record = {}; findByUserId(userId: string): Cart { - return this.userCarts[ userId ]; + return this.userCarts[userId]; } - createByUserId(userId: string) { + createByUserId(userId: string): Cart { const id = v4(); - const userCart = { + const currentTime = new Date().toISOString(); + const userCart: Cart = { id, + user_id: userId, items: [], + created_at: currentTime, + updated_at: currentTime, + status: CartStatuses.OPEN }; - this.userCarts[ userId ] = userCart; + this.userCarts[userId] = userCart; return userCart; } @@ -51,5 +54,4 @@ export class CartService { removeByUserId(userId): void { this.userCarts[ userId ] = null; } - -} +} \ No newline at end of file