Skip to content

Commit 3ee0d14

Browse files
committed
Docker is working, clean up backend
1 parent e78c2db commit 3ee0d14

39 files changed

+317
-364
lines changed

.env

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
DATABASE_URL=mysql://root:password@db:3306/cedb
3+
MYSQL_DATABASE=cedb
4+
MYSQL_ROOT_PASSWORD=password
5+
6+
MYSQLDB_LOCAL_PORT=3306
7+
MYSQLDB_DOCKER_PORT=3306
8+
9+
NODE_LOCAL_PORT=8888
10+
NODE_DOCKER_PORT=8888
11+
12+
CLIENT_ORIGIN=http://127.0.0.1:8888
13+
CLIENT_API_BASE_URL=http://127.0.0.1:6868/api
14+
15+
REACT_LOCAL_PORT=8080
16+
REACT_DOCKER_PORT=8080

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ dist
1717
dist-ssr
1818
*.local
1919

20-
.env
2120
*docs
2221

2322

@@ -33,3 +32,8 @@ frontend/docs
3332

3433
backend/.idea
3534
frontend/.idea
35+
36+
backend/dbdata
37+
38+
# TODO: For demo purposes we allow .env to be pushed
39+
# .env

README.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<p align="center">
2+
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo-small.svg" width="200" alt="Nest Logo" /></a>
3+
</p>
4+
5+
[circleci-image]: https://img.shields.io/circleci/build/github/nestjs/nest/master?token=abc123def456
6+
[circleci-url]: https://circleci.com/gh/nestjs/nest
7+
8+
<p align="center">A progressive <a href="http://nodejs.org" target="_blank">Node.js</a> framework for building efficient and scalable server-side applications.</p>
9+
<p align="center">
10+
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
11+
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
12+
<a href="https://www.npmjs.com/~nestjscore" target="_blank"><img src="https://img.shields.io/npm/dm/@nestjs/common.svg" alt="NPM Downloads" /></a>
13+
<a href="https://circleci.com/gh/nestjs/nest" target="_blank"><img src="https://img.shields.io/circleci/build/github/nestjs/nest/master" alt="CircleCI" /></a>
14+
<a href="https://coveralls.io/github/nestjs/nest?branch=master" target="_blank"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#9" alt="Coverage" /></a>
15+
<a href="https://discord.gg/G7Qnnhy" target="_blank"><img src="https://img.shields.io/badge/discord-online-brightgreen.svg" alt="Discord"/></a>
16+
<a href="https://opencollective.com/nest#backer" target="_blank"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
17+
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
18+
<a href="https://paypal.me/kamilmysliwiec" target="_blank"><img src="https://img.shields.io/badge/Donate-PayPal-ff3f59.svg"/></a>
19+
<a href="https://opencollective.com/nest#sponsor" target="_blank"><img src="https://img.shields.io/badge/Support%20us-Open%20Collective-41B883.svg" alt="Support us"></a>
20+
<a href="https://twitter.com/nestframework" target="_blank"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
21+
</p>
22+
<!--[![Backers on Open Collective](https://opencollective.com/nest/backers/badge.svg)](https://opencollective.com/nest#backer)
23+
[![Sponsors on Open Collective](https://opencollective.com/nest/sponsors/badge.svg)](https://opencollective.com/nest#sponsor)-->
24+
25+
## Description
26+
27+
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
28+
29+
## Installation
30+
31+
```bash
32+
$ pnpm install
33+
```
34+
35+
## Running the app
36+
37+
```bash
38+
# development
39+
$ pnpm run start
40+
41+
# watch mode
42+
$ pnpm run start:dev
43+
44+
# production mode
45+
$ pnpm run start:prod
46+
```
47+
48+
## Test
49+
50+
```bash
51+
# unit tests
52+
$ pnpm run test
53+
54+
# e2e tests
55+
$ pnpm run test:e2e
56+
57+
# test coverage
58+
$ pnpm run test:cov
59+
```
60+
61+
##
62+
Use Prisma CLI to apply migrations and generate the Prisma client:
63+
64+
```bash
65+
npx prisma migrate dev
66+
npx prisma generate
67+
68+
69+
# Docker commands
70+
docker system prune -a
71+
docker-compose up db
72+
73+
```
74+
75+
## License
76+
77+
Nest is [MIT licensed](LICENSE).

backend/.env

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Environment variables declared in this file are automatically made available to Prisma.
2+
# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema
3+
4+
# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
5+
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
6+
7+
DATABASE_URL=mysql://root:password@localhost:3306/cedb
8+
9+
NODE_LOCAL_PORT=8888
10+
NODE_DOCKER_PORT=8888

backend/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ EXPOSE $NODE_DOCKER_PORT
2525

2626

2727
CMD ["./waitForIt.sh", "db:3306", "--", "./migratePrisma.sh"]
28-
CMD ["npx","prisma", "migrate", "dev"]
2928

29+
CMD ["npx","prisma", "migrate", "dev"]
3030
CMD ["pnpm", "run", "start"]
31+
3132
#CMD ["node","dist/main.js"]
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
-- AlterTable
2+
ALTER TABLE `Review` ADD COLUMN `cafesId` INTEGER NULL;
3+
4+
-- AlterTable
5+
ALTER TABLE `Tag` ADD COLUMN `cafesId` INTEGER NULL;
6+
7+
-- CreateTable
8+
CREATE TABLE `Cafes` (
9+
`id` INTEGER NOT NULL AUTO_INCREMENT,
10+
`name` VARCHAR(191) NOT NULL,
11+
`description` VARCHAR(191) NOT NULL,
12+
`employeees` INTEGER NOT NULL,
13+
`logo` VARCHAR(191) NOT NULL,
14+
`location` VARCHAR(191) NOT NULL,
15+
16+
UNIQUE INDEX `Cafes_name_key`(`name`),
17+
PRIMARY KEY (`id`)
18+
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
19+
20+
-- CreateTable
21+
CREATE TABLE `Employees` (
22+
`id` INTEGER NOT NULL AUTO_INCREMENT,
23+
`name` VARCHAR(191) NOT NULL,
24+
`email_address` VARCHAR(191) NOT NULL,
25+
`phone_number` VARCHAR(191) NOT NULL,
26+
`days_worked` INTEGER NOT NULL,
27+
`cafe` VARCHAR(191) NOT NULL,
28+
29+
UNIQUE INDEX `Employees_name_key`(`name`),
30+
PRIMARY KEY (`id`)
31+
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- DropIndex
2+
DROP INDEX `Employees_name_key` ON `Employees`;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
Warnings:
3+
4+
- You are about to drop the column `employeees` on the `Cafes` table. All the data in the column will be lost.
5+
- A unique constraint covering the columns `[cafe]` on the table `Employees` will be added. If there are existing duplicate values, this will fail.
6+
- Added the required column `employees` to the `Cafes` table without a default value. This is not possible if the table is not empty.
7+
8+
*/
9+
-- AlterTable
10+
ALTER TABLE `Cafes` DROP COLUMN `employeees`,
11+
ADD COLUMN `employees` INTEGER NOT NULL;
12+
13+
-- CreateIndex
14+
CREATE UNIQUE INDEX `Employees_cafe_key` ON `Employees`(`cafe`);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Warnings:
3+
4+
- You are about to drop the `Description` table. If the table is not empty, all the data it contains will be lost.
5+
- You are about to drop the `Product` table. If the table is not empty, all the data it contains will be lost.
6+
- You are about to drop the `Review` table. If the table is not empty, all the data it contains will be lost.
7+
- You are about to drop the `Tag` table. If the table is not empty, all the data it contains will be lost.
8+
- You are about to drop the `_ProductToTag` table. If the table is not empty, all the data it contains will be lost.
9+
10+
*/
11+
-- DropForeignKey
12+
ALTER TABLE `Description` DROP FOREIGN KEY `Description_productId_fkey`;
13+
14+
-- DropForeignKey
15+
ALTER TABLE `Review` DROP FOREIGN KEY `Review_productId_fkey`;
16+
17+
-- DropForeignKey
18+
ALTER TABLE `_ProductToTag` DROP FOREIGN KEY `_ProductToTag_A_fkey`;
19+
20+
-- DropForeignKey
21+
ALTER TABLE `_ProductToTag` DROP FOREIGN KEY `_ProductToTag_B_fkey`;
22+
23+
-- DropTable
24+
DROP TABLE `Description`;
25+
26+
-- DropTable
27+
DROP TABLE `Product`;
28+
29+
-- DropTable
30+
DROP TABLE `Review`;
31+
32+
-- DropTable
33+
DROP TABLE `Tag`;
34+
35+
-- DropTable
36+
DROP TABLE `_ProductToTag`;

backend/prisma/schema.prisma

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,20 @@ datasource db {
1010
url = env("DATABASE_URL")
1111
}
1212

13-
model Product {
14-
id Int @id @default(autoincrement())
15-
name String @unique
16-
createdAt DateTime @default(now())
17-
updatedAt DateTime @updatedAt
18-
price Float
19-
sale Boolean @default(false)
20-
availibility Availibility
21-
reviews Review[]
22-
tags Tag[]
23-
description Description?
13+
model Cafes {
14+
id Int @id @default(autoincrement())
15+
name String @unique
16+
description String
17+
employees Int
18+
logo String
19+
location String
2420
}
2521

26-
model Description {
27-
id Int @id @default(autoincrement())
28-
content String
29-
product Product @relation(fields: [productId], references: [id])
30-
productId Int @unique
31-
}
32-
33-
model Review {
34-
id Int @id @default(autoincrement())
35-
title String
36-
content String
37-
rating Int
38-
product Product @relation(fields: [productId], references: [id])
39-
productId Int
40-
}
41-
42-
model Tag {
43-
id Int @id @default(autoincrement())
44-
content String
45-
products Product[]
46-
}
47-
48-
enum Availibility {
49-
IN_STORE
50-
ONLINE
22+
model Employees {
23+
id Int @id @default(autoincrement())
24+
name String
25+
email_address String
26+
phone_number String
27+
days_worked Int
28+
cafe String @unique
5129
}

backend/src/app.controller.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ describe('AppController', () => {
1515
});
1616

1717
describe('root', () => {
18-
it('should return "Hello World!"', () => {
19-
expect(appController.getHello()).toBe('Hello World!');
18+
it('should return "'Café Page!'"', () => {
19+
expect(appController.getHello()).toBe(''Café Page!'');
2020
});
2121
});
2222
});

backend/src/app.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import { Injectable } from '@nestjs/common';
33
@Injectable()
44
export class AppService {
55
getHello(): string {
6-
return 'Hello World!';
6+
return 'Café Page!';
77
}
88
}

backend/src/cafes/cafes.controller.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
import { Controller, Get, Post, Body, Patch, Param, Delete } from '@nestjs/common';
1+
import {
2+
Controller,
3+
Get,
4+
Post,
5+
Body,
6+
Patch,
7+
Param,
8+
Delete,
9+
} from '@nestjs/common';
10+
import { Prisma } from '@prisma/client';
211
import { CafesService } from './cafes.service';
3-
import { CreateCafeDto } from './dto/create-cafe.dto';
4-
import { UpdateCafeDto } from './dto/update-cafe.dto';
512

613
@Controller('cafes')
714
export class CafesController {
815
constructor(private readonly cafesService: CafesService) {}
916

1017
@Post()
11-
create(@Body() createCafeDto: CreateCafeDto) {
18+
create(@Body() createCafeDto: Prisma.CafesCreateInput) {
1219
return this.cafesService.create(createCafeDto);
1320
}
1421

@@ -23,7 +30,10 @@ export class CafesController {
2330
}
2431

2532
@Patch(':id')
26-
update(@Param('id') id: string, @Body() updateCafeDto: UpdateCafeDto) {
33+
update(
34+
@Param('id') id: string,
35+
@Body() updateCafeDto: Prisma.CafesUpdateInput,
36+
) {
2737
return this.cafesService.update(+id, updateCafeDto);
2838
}
2939

backend/src/cafes/cafes.service.ts

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,41 @@
11
import { Injectable } from '@nestjs/common';
2-
import { CreateCafeDto } from './dto/create-cafe.dto';
3-
import { UpdateCafeDto } from './dto/update-cafe.dto';
2+
import { Prisma } from '@prisma/client';
3+
import { DatabaseService } from '../database/database.service';
44

55
@Injectable()
66
export class CafesService {
7-
create(createCafeDto: CreateCafeDto) {
8-
return 'This action adds a new cafe';
7+
constructor(private readonly databaseService: DatabaseService) {}
8+
9+
async create(createCafeDto: Prisma.CafesCreateInput) {
10+
return this.databaseService.cafes.create({ data: createCafeDto });
911
}
1012

11-
findAll() {
12-
return `This action returns all cafes`;
13+
async findAll() {
14+
return this.databaseService.cafes.findMany({});
1315
}
1416

15-
findOne(id: number) {
16-
return `This action returns a #${id} cafe`;
17+
async findOne(id: number) {
18+
return this.databaseService.cafes.findUnique({
19+
where: {
20+
id,
21+
},
22+
});
1723
}
1824

19-
update(id: number, updateCafeDto: UpdateCafeDto) {
20-
return `This action updates a #${id} cafe`;
25+
async update(id: number, updateCafeDto: Prisma.CafesUpdateInput) {
26+
return this.databaseService.cafes.update({
27+
where: {
28+
id,
29+
},
30+
data: updateCafeDto,
31+
});
2132
}
2233

23-
remove(id: number) {
24-
return `This action removes a #${id} cafe`;
34+
async remove(id: number) {
35+
return this.databaseService.cafes.delete({
36+
where: {
37+
id,
38+
},
39+
});
2540
}
2641
}

backend/src/cafes/dto/create-cafe.dto.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

backend/src/cafes/dto/update-cafe.dto.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

backend/src/cafes/entities/cafe.entity.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

backend/src/employees/dto/create-employee.dto.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)