Skip to content

Commit 01a2896

Browse files
committed
first commit
1 parent 4681063 commit 01a2896

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+816
-1781
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,6 @@ Nest is an MIT-licensed open source project. It can grow thanks to the sponsors
7171
## License
7272

7373
Nest is [MIT licensed](LICENSE).
74+
75+
## Prisma Initialize
76+
- This project source use prisma as ORM, so to start prisma use this command: `yarn prisma init`

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"@nestjs/passport": "^10.0.2",
3333
"@nestjs/platform-express": "^10.2.5",
3434
"@nestjs/serve-static": "^4.0.0",
35+
"@prisma/client": "5.19.1",
3536
"@types/graphql-upload": "^16.0.2",
3637
"@types/nodemailer": "^6.4.11",
3738
"@types/passport-google-oauth20": "^2.0.13",
@@ -61,7 +62,7 @@
6162
"passport-google-oauth20": "^2.0.0",
6263
"passport-jwt": "^4.0.1",
6364
"passport-local": "^1.0.0",
64-
"prisma": "^5.2.0",
65+
"prisma": "^5.19.1",
6566
"reflect-metadata": "^0.1.13",
6667
"rxjs": "^7.8.1",
6768
"uuid": "^9.0.1"
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
-- CreateTable
2+
CREATE TABLE `user` (
3+
`id` INTEGER NOT NULL AUTO_INCREMENT,
4+
`email` VARCHAR(100) NULL,
5+
`username` VARCHAR(100) NULL,
6+
`password` VARCHAR(100) NULL,
7+
`token_cache_login` VARCHAR(100) NULL,
8+
`created_date` DATETIME(0) NULL DEFAULT CURRENT_TIMESTAMP(0),
9+
`modify_date` DATETIME(0) NULL DEFAULT CURRENT_TIMESTAMP(0),
10+
11+
PRIMARY KEY (`id`)
12+
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
13+
14+
-- CreateTable
15+
CREATE TABLE `session` (
16+
`id` INTEGER NOT NULL AUTO_INCREMENT,
17+
`created_at` DATETIME(0) NULL DEFAULT CURRENT_TIMESTAMP(0),
18+
`updated_at` DATETIME(0) NULL DEFAULT CURRENT_TIMESTAMP(0),
19+
`userID` INTEGER NULL,
20+
`accessToken` VARCHAR(200) NULL,
21+
`refreshToken` VARCHAR(200) NULL,
22+
23+
INDEX `userID`(`userID`),
24+
PRIMARY KEY (`id`)
25+
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
26+
27+
-- AddForeignKey
28+
ALTER TABLE `session` ADD CONSTRAINT `session_ibfk_1` FOREIGN KEY (`userID`) REFERENCES `user`(`id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
-- CreateTable
2+
CREATE TABLE `device` (
3+
`id` INTEGER NOT NULL AUTO_INCREMENT,
4+
`userID` INTEGER NULL,
5+
`current_state` INTEGER NULL,
6+
`device_name` VARCHAR(200) NULL,
7+
`created_at` DATETIME(0) NULL DEFAULT CURRENT_TIMESTAMP(0),
8+
`updated_at` DATETIME(0) NULL DEFAULT CURRENT_TIMESTAMP(0),
9+
10+
INDEX `userID`(`userID`),
11+
PRIMARY KEY (`id`)
12+
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
13+
14+
-- CreateTable
15+
CREATE TABLE `command` (
16+
`id` INTEGER NOT NULL AUTO_INCREMENT,
17+
`deviceID` INTEGER NULL,
18+
`command` VARCHAR(200) NULL,
19+
`created_at` DATETIME(0) NULL DEFAULT CURRENT_TIMESTAMP(0),
20+
`updated_at` DATETIME(0) NULL DEFAULT CURRENT_TIMESTAMP(0),
21+
22+
INDEX `deviceID`(`deviceID`),
23+
PRIMARY KEY (`id`)
24+
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
25+
26+
-- AddForeignKey
27+
ALTER TABLE `device` ADD CONSTRAINT `device_ibfk_1` FOREIGN KEY (`userID`) REFERENCES `user`(`id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
28+
29+
-- AddForeignKey
30+
ALTER TABLE `command` ADD CONSTRAINT `command_ibfk_1` FOREIGN KEY (`deviceID`) REFERENCES `device`(`id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
31+
32+
-- AddForeignKey
33+
ALTER TABLE `command` ADD CONSTRAINT `command_ibfk_2` FOREIGN KEY (`deviceID`) REFERENCES `user`(`id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- DropForeignKey
2+
ALTER TABLE `device` DROP FOREIGN KEY `device_ibfk_1`;
3+
4+
-- AlterTable
5+
ALTER TABLE `command` ADD COLUMN `receiver` VARCHAR(200) NULL,
6+
ADD COLUMN `sender` VARCHAR(200) NULL;
7+
8+
-- AddForeignKey
9+
ALTER TABLE `device` ADD CONSTRAINT `device_ibfk_1` FOREIGN KEY (`userID`) REFERENCES `user`(`id`) ON DELETE CASCADE ON UPDATE RESTRICT;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
Warnings:
3+
4+
- A unique constraint covering the columns `[device_name]` on the table `device` will be added. If there are existing duplicate values, this will fail.
5+
- A unique constraint covering the columns `[email]` on the table `user` will be added. If there are existing duplicate values, this will fail.
6+
7+
*/
8+
-- CreateIndex
9+
CREATE UNIQUE INDEX `device_device_name_key` ON `device`(`device_name`);
10+
11+
-- CreateIndex
12+
CREATE UNIQUE INDEX `user_email_key` ON `user`(`email`);

prisma/migrations/migration_lock.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Please do not edit this file manually
2+
# It should be added in your version-control system (i.e. Git)
3+
provider = "mysql"

prisma/schema.prisma

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// This is your Prisma schema file,
2+
// learn more about it in the docs: https://pris.ly/d/prisma-schema
3+
4+
// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
5+
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init
6+
7+
generator client {
8+
provider = "prisma-client-js"
9+
}
10+
11+
datasource db {
12+
provider = "mysql"
13+
url = env("DATABASE_URL")
14+
}
15+
16+
model user {
17+
id Int @id @default(autoincrement())
18+
email String? @unique @db.VarChar(100)
19+
username String? @db.VarChar(100)
20+
password String? @db.VarChar(100)
21+
22+
token_cache_login String? @db.VarChar(100)
23+
session session[]
24+
device device[]
25+
command command[]
26+
27+
created_date DateTime? @default(now()) @db.DateTime(0)
28+
modify_date DateTime? @default(now()) @db.DateTime(0)
29+
}
30+
31+
model session {
32+
id Int @id @default(autoincrement())
33+
created_at DateTime? @default(now()) @db.DateTime(0)
34+
updated_at DateTime? @default(now()) @db.DateTime(0)
35+
userID Int?
36+
accessToken String? @db.VarChar(200)
37+
refreshToken String? @db.VarChar(200)
38+
user user? @relation(fields: [userID], references: [id], onDelete: Restrict, onUpdate: Restrict, map: "session_ibfk_1")
39+
40+
@@index([userID], map: "userID")
41+
}
42+
43+
model device {
44+
id Int @id @default(autoincrement())
45+
userID Int?
46+
current_state Int?
47+
device_name String? @unique @db.VarChar(200)
48+
user user? @relation(fields: [userID], references: [id], onDelete: Cascade, onUpdate: Restrict, map: "device_ibfk_1")
49+
created_at DateTime? @default(now()) @db.DateTime(0)
50+
updated_at DateTime? @default(now()) @db.DateTime(0)
51+
52+
command command[]
53+
54+
@@index([userID], map: "userID")
55+
}
56+
57+
model command {
58+
id Int @id @default(autoincrement())
59+
deviceID Int?
60+
command String? @db.VarChar(200)
61+
sender String? @db.VarChar(200)
62+
receiver String? @db.VarChar(200)
63+
64+
created_at DateTime? @default(now()) @db.DateTime(0)
65+
updated_at DateTime? @default(now()) @db.DateTime(0)
66+
67+
device device? @relation(fields: [deviceID], references: [id], onDelete: Restrict, onUpdate: Restrict, map: "command_ibfk_1")
68+
user user? @relation(fields: [deviceID], references: [id], onDelete: Restrict, onUpdate: Restrict, map: "command_ibfk_2")
69+
70+
@@index([deviceID], map: "deviceID")
71+
}

src/app.module.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,11 @@ import { HttpModule } from "@nestjs/axios";
1010

1111
import { UserModule } from "./modules/user/user.module";
1212
import { AuthenticateModule } from "./modules/authenticate/authenticate.module";
13-
import { BlogModule } from "./modules/blog/blog.module";
14-
import { ProductModule } from "./modules/product/product.module";
1513
import { appConfig, mailConfig } from "./config";
1614
import { MailModule } from "./modules/mail/mail.module";
17-
import { OrderModule } from "./modules/order/order.module";
1815
import { FileModule } from "./modules/file/file.module";
1916
import { AppController } from "./app.controller";
2017
import { ContactModule } from "./modules/contact/contact.module";
21-
import { ApiModule } from "./modules/api/api.module";
22-
import { AirMonitorModule } from './modules/air-monitor/air-monitor.module';
2318
import { DeviceModule } from './modules/device/device.module';
2419

2520
@Module({
@@ -59,14 +54,9 @@ import { DeviceModule } from './modules/device/device.module';
5954
PassportModule.register({ session: true }),
6055
UserModule,
6156
AuthenticateModule,
62-
BlogModule,
63-
ProductModule,
6457
MailModule,
65-
OrderModule,
6658
FileModule,
6759
ContactModule,
68-
ApiModule,
69-
AirMonitorModule,
7060
DeviceModule,
7161
],
7262
controllers: [AppController],

src/modules/air-monitor/air-monitor.module.ts

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

src/modules/air-monitor/air-monitor.resolver.ts

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

src/modules/air-monitor/air-monitor.service.ts

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

src/modules/air-monitor/dto/input.dto.ts

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

src/modules/air-monitor/dto/query.dto.ts

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

0 commit comments

Comments
 (0)