kybernus 2.1.1 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/templates/java-spring/clean/infra/main.tf.hbs +42 -18
- package/templates/java-spring/clean/infra/modules/ecs/main.tf.hbs +217 -6
- package/templates/java-spring/clean/infra/modules/rds/main.tf.hbs +15 -15
- package/templates/java-spring/clean/infra/modules/vpc/main.tf.hbs +170 -30
- package/templates/java-spring/hexagonal/infra/main.tf.hbs +42 -18
- package/templates/java-spring/hexagonal/infra/modules/ecs/main.tf.hbs +217 -6
- package/templates/java-spring/hexagonal/infra/modules/rds/main.tf.hbs +15 -15
- package/templates/java-spring/hexagonal/infra/modules/vpc/main.tf.hbs +170 -30
- package/templates/java-spring/mvc/infra/main.tf.hbs +42 -18
- package/templates/java-spring/mvc/infra/modules/ecs/main.tf.hbs +217 -6
- package/templates/java-spring/mvc/infra/modules/rds/main.tf.hbs +15 -15
- package/templates/java-spring/mvc/infra/modules/vpc/main.tf.hbs +170 -30
- package/templates/java-spring/mvc/src/main/java/{{packagePath}}/controller/AuthController.java.hbs +38 -42
- package/templates/java-spring/mvc/src/main/java/{{packagePath}}/controller/ItemController.java.hbs +42 -0
- package/templates/java-spring/mvc/src/main/java/{{packagePath}}/controller/PaymentsController.java.hbs +65 -22
- package/templates/java-spring/mvc/src/main/java/{{packagePath}}/model/Item.java.hbs +38 -0
- package/templates/java-spring/mvc/src/main/java/{{packagePath}}/model/User.java.hbs +41 -0
- package/templates/java-spring/mvc/src/main/java/{{packagePath}}/repository/ItemRepository.java.hbs +9 -0
- package/templates/java-spring/mvc/src/main/java/{{packagePath}}/repository/UserRepository.java.hbs +13 -0
- package/templates/java-spring/mvc/src/main/java/{{packagePath}}/service/AuthService.java.hbs +62 -0
- package/templates/java-spring/mvc/src/main/java/{{packagePath}}/service/StripeService.java.hbs +18 -18
- package/templates/java-spring/mvc/src/main/java/{{packagePath}}/{{projectNamePascalCase}}Application.java.hbs +2 -0
- package/templates/nestjs/clean/infra/main.tf.hbs +42 -18
- package/templates/nestjs/clean/infra/modules/ecs/main.tf.hbs +217 -6
- package/templates/nestjs/clean/infra/modules/rds/main.tf.hbs +15 -15
- package/templates/nestjs/clean/infra/modules/vpc/main.tf.hbs +170 -30
- package/templates/nestjs/hexagonal/infra/main.tf.hbs +42 -18
- package/templates/nestjs/hexagonal/infra/modules/ecs/main.tf.hbs +217 -6
- package/templates/nestjs/hexagonal/infra/modules/rds/main.tf.hbs +15 -15
- package/templates/nestjs/hexagonal/infra/modules/vpc/main.tf.hbs +170 -30
- package/templates/nestjs/mvc/infra/main.tf.hbs +42 -18
- package/templates/nestjs/mvc/infra/modules/ecs/main.tf.hbs +217 -6
- package/templates/nestjs/mvc/infra/modules/rds/main.tf.hbs +15 -15
- package/templates/nestjs/mvc/infra/modules/vpc/main.tf.hbs +170 -30
- package/templates/nestjs/mvc/package.json.hbs +6 -2
- package/templates/nestjs/mvc/prisma/schema.prisma.hbs +31 -0
- package/templates/nestjs/mvc/src/app.module.ts.hbs +3 -1
- package/templates/nestjs/mvc/src/auth/auth.service.ts.hbs +34 -31
- package/templates/nestjs/mvc/src/payments/payments.service.ts.hbs +26 -6
- package/templates/nestjs/mvc/src/prisma/prisma.module.ts.hbs +9 -0
- package/templates/nestjs/mvc/src/prisma/prisma.service.ts.hbs +15 -0
- package/templates/nestjs/mvc/src/services/items.service.ts.hbs +33 -20
- package/templates/nextjs/mvc/infra/main.tf.hbs +42 -18
- package/templates/nextjs/mvc/infra/modules/ecs/main.tf.hbs +217 -6
- package/templates/nextjs/mvc/infra/modules/rds/main.tf.hbs +15 -15
- package/templates/nextjs/mvc/infra/modules/vpc/main.tf.hbs +170 -30
- package/templates/nextjs/mvc/package.json.hbs +1 -0
- package/templates/nextjs/mvc/prisma/schema.prisma.hbs +60 -6
- package/templates/nextjs/mvc/src/app/api/webhook/route.ts.hbs +23 -18
- package/templates/nodejs-express/clean/infra/main.tf.hbs +42 -18
- package/templates/nodejs-express/clean/infra/modules/ecs/main.tf.hbs +217 -6
- package/templates/nodejs-express/clean/infra/modules/rds/main.tf.hbs +15 -15
- package/templates/nodejs-express/clean/infra/modules/vpc/main.tf.hbs +170 -30
- package/templates/nodejs-express/hexagonal/infra/main.tf.hbs +42 -18
- package/templates/nodejs-express/hexagonal/infra/modules/ecs/main.tf.hbs +217 -6
- package/templates/nodejs-express/hexagonal/infra/modules/rds/main.tf.hbs +15 -15
- package/templates/nodejs-express/hexagonal/infra/modules/vpc/main.tf.hbs +170 -30
- package/templates/nodejs-express/mvc/infra/main.tf.hbs +42 -18
- package/templates/nodejs-express/mvc/infra/modules/ecs/main.tf.hbs +217 -6
- package/templates/nodejs-express/mvc/infra/modules/rds/main.tf.hbs +15 -15
- package/templates/nodejs-express/mvc/infra/modules/vpc/main.tf.hbs +170 -30
- package/templates/nodejs-express/mvc/package.json.hbs +8 -4
- package/templates/nodejs-express/mvc/prisma/schema.prisma.hbs +31 -0
- package/templates/nodejs-express/mvc/src/config/database.ts.hbs +2 -9
- package/templates/nodejs-express/mvc/src/controllers/auth.controller.ts.hbs +40 -58
- package/templates/nodejs-express/mvc/src/controllers/items.controller.ts.hbs +29 -0
- package/templates/nodejs-express/mvc/src/models/README.md.hbs +10 -0
- package/templates/nodejs-express/mvc/src/prisma/client.ts.hbs +3 -0
- package/templates/nodejs-express/mvc/src/services/auth.service.ts.hbs +71 -0
- package/templates/nodejs-express/mvc/src/services/stripe.service.ts.hbs +35 -25
- package/templates/python-fastapi/clean/infra/main.tf.hbs +42 -18
- package/templates/python-fastapi/clean/infra/modules/ecs/main.tf.hbs +217 -6
- package/templates/python-fastapi/clean/infra/modules/rds/main.tf.hbs +15 -15
- package/templates/python-fastapi/clean/infra/modules/vpc/main.tf.hbs +170 -30
- package/templates/python-fastapi/hexagonal/infra/main.tf.hbs +42 -18
- package/templates/python-fastapi/hexagonal/infra/modules/ecs/main.tf.hbs +217 -6
- package/templates/python-fastapi/hexagonal/infra/modules/rds/main.tf.hbs +15 -15
- package/templates/python-fastapi/hexagonal/infra/modules/vpc/main.tf.hbs +170 -30
- package/templates/python-fastapi/mvc/app/controllers/auth.py.hbs +25 -16
- package/templates/python-fastapi/mvc/app/controllers/items.py.hbs +9 -7
- package/templates/python-fastapi/mvc/app/controllers/payments.py.hbs +42 -15
- package/templates/python-fastapi/mvc/app/database.py.hbs +17 -0
- package/templates/python-fastapi/mvc/app/main.py.hbs +4 -0
- package/templates/python-fastapi/mvc/app/models/item.py.hbs +11 -8
- package/templates/python-fastapi/mvc/app/models/user.py.hbs +15 -0
- package/templates/python-fastapi/mvc/app/repositories/item_repository.py.hbs +15 -0
- package/templates/python-fastapi/mvc/app/repositories/user_repository.py.hbs +15 -0
- package/templates/python-fastapi/mvc/app/services/item_service.py.hbs +17 -19
- package/templates/python-fastapi/mvc/infra/main.tf.hbs +42 -18
- package/templates/python-fastapi/mvc/infra/modules/ecs/main.tf.hbs +217 -6
- package/templates/python-fastapi/mvc/infra/modules/rds/main.tf.hbs +15 -15
- package/templates/python-fastapi/mvc/infra/modules/vpc/main.tf.hbs +170 -30
|
@@ -10,81 +10,213 @@ variable "environment" {
|
|
|
10
10
|
|
|
11
11
|
# VPC
|
|
12
12
|
resource "aws_vpc" "main" {
|
|
13
|
-
cidr_block
|
|
13
|
+
cidr_block = "10.0.0.0/16"
|
|
14
14
|
enable_dns_hostnames = true
|
|
15
|
-
enable_dns_support
|
|
15
|
+
enable_dns_support = true
|
|
16
16
|
|
|
17
17
|
tags = {
|
|
18
|
-
Name
|
|
18
|
+
Name = "${var.app_name}-${var.environment}-vpc"
|
|
19
19
|
Environment = var.environment
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
# Internet Gateway
|
|
24
|
+
resource "aws_internet_gateway" "main" {
|
|
25
|
+
vpc_id = aws_vpc.main.id
|
|
26
|
+
|
|
27
|
+
tags = {
|
|
28
|
+
Name = "${var.app_name}-${var.environment}-igw"
|
|
29
|
+
Environment = var.environment
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
# Data source for AZs
|
|
34
|
+
data "aws_availability_zones" "available" {
|
|
35
|
+
state = "available"
|
|
36
|
+
}
|
|
37
|
+
|
|
23
38
|
# Public Subnets
|
|
24
39
|
resource "aws_subnet" "public" {
|
|
25
|
-
count
|
|
40
|
+
count = 2
|
|
41
|
+
vpc_id = aws_vpc.main.id
|
|
42
|
+
cidr_block = "10.0.${count.index + 1}.0/24"
|
|
43
|
+
availability_zone = data.aws_availability_zones.available.names[count.index]
|
|
44
|
+
map_public_ip_on_launch = true
|
|
45
|
+
|
|
46
|
+
tags = {
|
|
47
|
+
Name = "${var.app_name}-${var.environment}-public-${count.index + 1}"
|
|
48
|
+
Environment = var.environment
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
# Route Table for Public Subnets
|
|
53
|
+
resource "aws_route_table" "public" {
|
|
26
54
|
vpc_id = aws_vpc.main.id
|
|
27
|
-
cidr_block = "10.0.${count.index + 1}.0/24"
|
|
28
|
-
availability_zone = data.aws_availability_zones.available.names[count.index]
|
|
29
55
|
|
|
30
|
-
|
|
56
|
+
route {
|
|
57
|
+
cidr_block = "0.0.0.0/0"
|
|
58
|
+
gateway_id = aws_internet_gateway.main.id
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
tags = {
|
|
62
|
+
Name = "${var.app_name}-${var.environment}-public-rt"
|
|
63
|
+
Environment = var.environment
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
# Association for Public Subnets
|
|
68
|
+
resource "aws_route_table_association" "public" {
|
|
69
|
+
count = 2
|
|
70
|
+
subnet_id = aws_subnet.public[count.index].id
|
|
71
|
+
route_table_id = aws_route_table.public.id
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
# Elastic IP for NAT Gateway
|
|
75
|
+
resource "aws_eip" "nat" {
|
|
76
|
+
count = 1
|
|
77
|
+
domain = "vpc"
|
|
31
78
|
|
|
32
79
|
tags = {
|
|
33
|
-
Name
|
|
80
|
+
Name = "${var.app_name}-${var.environment}-nat-eip"
|
|
81
|
+
Environment = var.environment
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
# NAT Gateway (single NAT for cost savings, can change to 1 per AZ for production if needed)
|
|
86
|
+
resource "aws_nat_gateway" "main" {
|
|
87
|
+
count = 1
|
|
88
|
+
allocation_id = aws_eip.nat[0].id
|
|
89
|
+
subnet_id = aws_subnet.public[0].id
|
|
90
|
+
|
|
91
|
+
depends_on = [aws_internet_gateway.main]
|
|
92
|
+
|
|
93
|
+
tags = {
|
|
94
|
+
Name = "${var.app_name}-${var.environment}-nat"
|
|
34
95
|
Environment = var.environment
|
|
35
96
|
}
|
|
36
97
|
}
|
|
37
98
|
|
|
38
99
|
# Private Subnets
|
|
39
100
|
resource "aws_subnet" "private" {
|
|
40
|
-
count
|
|
41
|
-
vpc_id
|
|
42
|
-
cidr_block
|
|
101
|
+
count = 2
|
|
102
|
+
vpc_id = aws_vpc.main.id
|
|
103
|
+
cidr_block = "10.0.${count.index + 10}.0/24"
|
|
43
104
|
availability_zone = data.aws_availability_zones.available.names[count.index]
|
|
44
105
|
|
|
45
106
|
tags = {
|
|
46
|
-
Name
|
|
107
|
+
Name = "${var.app_name}-${var.environment}-private-${count.index + 1}"
|
|
47
108
|
Environment = var.environment
|
|
48
109
|
}
|
|
49
110
|
}
|
|
50
111
|
|
|
51
|
-
#
|
|
52
|
-
resource "
|
|
112
|
+
# Route Table for Private Subnets
|
|
113
|
+
resource "aws_route_table" "private" {
|
|
53
114
|
vpc_id = aws_vpc.main.id
|
|
54
115
|
|
|
116
|
+
route {
|
|
117
|
+
cidr_block = "0.0.0.0/0"
|
|
118
|
+
nat_gateway_id = aws_nat_gateway.main[0].id
|
|
119
|
+
}
|
|
120
|
+
|
|
55
121
|
tags = {
|
|
56
|
-
Name
|
|
122
|
+
Name = "${var.app_name}-${var.environment}-private-rt"
|
|
57
123
|
Environment = var.environment
|
|
58
124
|
}
|
|
59
125
|
}
|
|
60
126
|
|
|
61
|
-
#
|
|
62
|
-
|
|
63
|
-
|
|
127
|
+
# Association for Private Subnets
|
|
128
|
+
resource "aws_route_table_association" "private" {
|
|
129
|
+
count = 2
|
|
130
|
+
subnet_id = aws_subnet.private[count.index].id
|
|
131
|
+
route_table_id = aws_route_table.private.id
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
# Security Group for Load Balancer (ALB)
|
|
135
|
+
resource "aws_security_group" "alb" {
|
|
136
|
+
name = "${var.app_name}-${var.environment}-alb-sg"
|
|
137
|
+
description = "Security group for ALB"
|
|
138
|
+
vpc_id = aws_vpc.main.id
|
|
139
|
+
|
|
140
|
+
ingress {
|
|
141
|
+
from_port = 80
|
|
142
|
+
to_port = 80
|
|
143
|
+
protocol = "tcp"
|
|
144
|
+
cidr_blocks = ["0.0.0.0/0"]
|
|
145
|
+
description = "Allow HTTP from anywhere"
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
ingress {
|
|
149
|
+
from_port = 443
|
|
150
|
+
to_port = 443
|
|
151
|
+
protocol = "tcp"
|
|
152
|
+
cidr_blocks = ["0.0.0.0/0"]
|
|
153
|
+
description = "Allow HTTPS from anywhere"
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
egress {
|
|
157
|
+
from_port = 0
|
|
158
|
+
to_port = 0
|
|
159
|
+
protocol = "-1"
|
|
160
|
+
cidr_blocks = ["0.0.0.0/0"]
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
tags = {
|
|
164
|
+
Name = "${var.app_name}-${var.environment}-alb-sg"
|
|
165
|
+
Environment = var.environment
|
|
166
|
+
}
|
|
64
167
|
}
|
|
65
168
|
|
|
66
|
-
# Security Group for
|
|
169
|
+
# Security Group for ECS Tasks
|
|
170
|
+
resource "aws_security_group" "ecs_tasks" {
|
|
171
|
+
name = "${var.app_name}-${var.environment}-ecs-tasks-sg"
|
|
172
|
+
description = "Security group for ECS tasks"
|
|
173
|
+
vpc_id = aws_vpc.main.id
|
|
174
|
+
|
|
175
|
+
ingress {
|
|
176
|
+
from_port = 0
|
|
177
|
+
to_port = 0
|
|
178
|
+
protocol = "-1"
|
|
179
|
+
security_groups = [aws_security_group.alb.id]
|
|
180
|
+
description = "Allow all traffic from ALB"
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
egress {
|
|
184
|
+
from_port = 0
|
|
185
|
+
to_port = 0
|
|
186
|
+
protocol = "-1"
|
|
187
|
+
cidr_blocks = ["0.0.0.0/0"]
|
|
188
|
+
description = "Allow all outbound traffic"
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
tags = {
|
|
192
|
+
Name = "${var.app_name}-${var.environment}-ecs-tasks-sg"
|
|
193
|
+
Environment = var.environment
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
# Security Group for Database (RDS)
|
|
67
198
|
resource "aws_security_group" "db" {
|
|
68
|
-
name
|
|
199
|
+
name = "${var.app_name}-${var.environment}-db-sg"
|
|
69
200
|
description = "Security group for database"
|
|
70
|
-
vpc_id
|
|
201
|
+
vpc_id = aws_vpc.main.id
|
|
71
202
|
|
|
72
203
|
ingress {
|
|
73
|
-
from_port
|
|
74
|
-
to_port
|
|
75
|
-
protocol
|
|
76
|
-
|
|
204
|
+
from_port = 5432
|
|
205
|
+
to_port = 5432
|
|
206
|
+
protocol = "tcp"
|
|
207
|
+
security_groups = [aws_security_group.ecs_tasks.id]
|
|
208
|
+
description = "Allow PostgreSQL access from ECS tasks"
|
|
77
209
|
}
|
|
78
210
|
|
|
79
211
|
egress {
|
|
80
|
-
from_port
|
|
81
|
-
to_port
|
|
82
|
-
protocol
|
|
212
|
+
from_port = 0
|
|
213
|
+
to_port = 0
|
|
214
|
+
protocol = "-1"
|
|
83
215
|
cidr_blocks = ["0.0.0.0/0"]
|
|
84
216
|
}
|
|
85
217
|
|
|
86
218
|
tags = {
|
|
87
|
-
Name
|
|
219
|
+
Name = "${var.app_name}-${var.environment}-db-sg"
|
|
88
220
|
Environment = var.environment
|
|
89
221
|
}
|
|
90
222
|
}
|
|
@@ -104,4 +236,12 @@ output "private_subnet_ids" {
|
|
|
104
236
|
|
|
105
237
|
output "db_security_group_id" {
|
|
106
238
|
value = aws_security_group.db.id
|
|
107
|
-
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
output "alb_security_group_id" {
|
|
242
|
+
value = aws_security_group.alb.id
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
output "ecs_tasks_security_group_id" {
|
|
246
|
+
value = aws_security_group.ecs_tasks.id
|
|
247
|
+
}
|
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
"build": "nest build",
|
|
8
8
|
"start": "node dist/main.js",
|
|
9
9
|
"lint": "eslint \"{src,test}/**/*.ts\"",
|
|
10
|
-
"test": "jest"
|
|
10
|
+
"test": "jest",
|
|
11
|
+
"db:generate": "prisma generate",
|
|
12
|
+
"db:push": "prisma db push"
|
|
11
13
|
},
|
|
12
14
|
"dependencies": {
|
|
13
15
|
"@nestjs/common": "^10.3.0",
|
|
@@ -16,6 +18,7 @@
|
|
|
16
18
|
"@nestjs/jwt": "^10.2.0",
|
|
17
19
|
"@nestjs/passport": "^10.0.3",
|
|
18
20
|
"@nestjs/platform-express": "^10.3.0",
|
|
21
|
+
"@prisma/client": "^5.10.2",
|
|
19
22
|
"bcryptjs": "^2.4.3",
|
|
20
23
|
"class-transformer": "^0.5.1",
|
|
21
24
|
"class-validator": "^0.14.1",
|
|
@@ -32,6 +35,7 @@
|
|
|
32
35
|
"@types/node": "^20.11.0",
|
|
33
36
|
"@types/passport-jwt": "^4.0.0",
|
|
34
37
|
"@types/uuid": "^9.0.7",
|
|
38
|
+
"prisma": "^5.10.2",
|
|
35
39
|
"typescript": "^5.3.3"
|
|
36
40
|
}
|
|
37
|
-
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
generator client {
|
|
2
|
+
provider = "prisma-client-js"
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
datasource db {
|
|
6
|
+
provider = "postgresql"
|
|
7
|
+
url = env("DATABASE_URL")
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
model User {
|
|
11
|
+
id String @id @default(uuid())
|
|
12
|
+
email String @unique
|
|
13
|
+
name String?
|
|
14
|
+
password String
|
|
15
|
+
stripeCustomerId String? @map("stripe_customer_id")
|
|
16
|
+
createdAt DateTime @default(now()) @map("created_at")
|
|
17
|
+
updatedAt DateTime @updatedAt @map("updated_at")
|
|
18
|
+
|
|
19
|
+
@@map("users")
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
model Item {
|
|
23
|
+
id String @id @default(uuid())
|
|
24
|
+
name String
|
|
25
|
+
description String?
|
|
26
|
+
price Float?
|
|
27
|
+
createdAt DateTime @default(now()) @map("created_at")
|
|
28
|
+
updatedAt DateTime @updatedAt @map("updated_at")
|
|
29
|
+
|
|
30
|
+
@@map("items")
|
|
31
|
+
}
|
|
@@ -4,14 +4,16 @@ import { ItemsModule } from './modules/items.module';
|
|
|
4
4
|
import { AuthModule } from './auth/auth.module';
|
|
5
5
|
import { PaymentsModule } from './payments/payments.module';
|
|
6
6
|
import { HealthController } from './controllers/health.controller';
|
|
7
|
+
import { PrismaModule } from './prisma/prisma.module';
|
|
7
8
|
|
|
8
9
|
@Module({
|
|
9
10
|
imports: [
|
|
10
11
|
ConfigModule.forRoot({ isGlobal: true }),
|
|
12
|
+
PrismaModule,
|
|
11
13
|
AuthModule,
|
|
12
14
|
PaymentsModule,
|
|
13
15
|
ItemsModule,
|
|
14
16
|
],
|
|
15
17
|
controllers: [HealthController],
|
|
16
18
|
})
|
|
17
|
-
export class AppModule {}
|
|
19
|
+
export class AppModule {}
|
|
@@ -1,43 +1,46 @@
|
|
|
1
|
-
import { Injectable } from '@nestjs/common';
|
|
1
|
+
import { Injectable, UnauthorizedException, BadRequestException } from '@nestjs/common';
|
|
2
2
|
import { JwtService } from '@nestjs/jwt';
|
|
3
3
|
import * as bcrypt from 'bcryptjs';
|
|
4
|
-
|
|
5
|
-
interface User {
|
|
6
|
-
id: string;
|
|
7
|
-
email: string;
|
|
8
|
-
name: string;
|
|
9
|
-
password: string;
|
|
10
|
-
}
|
|
4
|
+
import { PrismaService } from '../prisma/prisma.service';
|
|
11
5
|
|
|
12
6
|
@Injectable()
|
|
13
7
|
export class AuthService {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
constructor(
|
|
9
|
+
private jwtService: JwtService,
|
|
10
|
+
private prisma: PrismaService,
|
|
11
|
+
) {}
|
|
17
12
|
|
|
18
13
|
async register(email: string, name: string, password: string) {
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
const existingUser = await this.prisma.user.findUnique({
|
|
15
|
+
where: { email },
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
if (existingUser) {
|
|
19
|
+
throw new BadRequestException('User already exists');
|
|
21
20
|
}
|
|
22
21
|
|
|
23
22
|
const hashedPassword = await bcrypt.hash(password, 10);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
|
|
24
|
+
const user = await this.prisma.user.create({
|
|
25
|
+
data: {
|
|
26
|
+
email,
|
|
27
|
+
name,
|
|
28
|
+
password: hashedPassword,
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
|
|
32
32
|
const token = this.jwtService.sign({ sub: user.id, email: user.email });
|
|
33
33
|
|
|
34
34
|
return { token, user: { id: user.id, email: user.email, name: user.name } };
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
async login(email: string, password: string) {
|
|
38
|
-
const user = this.
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
const user = await this.prisma.user.findUnique({
|
|
39
|
+
where: { email },
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
if (users || !(await bcrypt.compare(password, user.password))) {
|
|
43
|
+
throw new UnauthorizedException('Invalid credentials');
|
|
41
44
|
}
|
|
42
45
|
|
|
43
46
|
const token = this.jwtService.sign({ sub: user.id, email: user.email });
|
|
@@ -45,11 +48,11 @@ export class AuthService {
|
|
|
45
48
|
}
|
|
46
49
|
|
|
47
50
|
async validateUser(userId: string) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return
|
|
51
|
+
const user = await this.prisma.user.findUnique({
|
|
52
|
+
where: { id: userId },
|
|
53
|
+
select: { id: true, email: true, name: true }
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
return user;
|
|
54
57
|
}
|
|
55
|
-
}
|
|
58
|
+
}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { Injectable } from '@nestjs/common';
|
|
2
2
|
import { ConfigService } from '@nestjs/config';
|
|
3
3
|
import Stripe from 'stripe';
|
|
4
|
+
import { PrismaService } from '../prisma/prisma.service';
|
|
4
5
|
|
|
5
6
|
@Injectable()
|
|
6
7
|
export class PaymentsService {
|
|
7
8
|
private stripe: Stripe;
|
|
8
9
|
|
|
9
|
-
constructor(
|
|
10
|
+
constructor(
|
|
11
|
+
private configService: ConfigService,
|
|
12
|
+
private prisma: PrismaService,
|
|
13
|
+
) {
|
|
10
14
|
this.stripe = new Stripe(configService.get('STRIPE_SECRET_KEY', ''), {
|
|
11
15
|
apiVersion: '2024-12-18.acacia',
|
|
12
16
|
});
|
|
@@ -31,13 +35,29 @@ export class PaymentsService {
|
|
|
31
35
|
|
|
32
36
|
switch (event.type) {
|
|
33
37
|
case 'checkout.session.completed':
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
{
|
|
39
|
+
const session = event.data.object as Stripe.Checkout.Session;
|
|
40
|
+
console.log('Checkout completed:', session.id);
|
|
41
|
+
// Match the session back to the user via client_reference_id or customer email
|
|
42
|
+
// await this.prisma.user.update({...});
|
|
43
|
+
}
|
|
44
|
+
break;
|
|
36
45
|
case 'customer.subscription.updated':
|
|
37
|
-
|
|
38
|
-
|
|
46
|
+
{
|
|
47
|
+
const subscription = event.data.object as Stripe.Subscription;
|
|
48
|
+
console.log('Subscription updated:', subscription.id);
|
|
49
|
+
// Update user's subscription status in DB
|
|
50
|
+
}
|
|
51
|
+
break;
|
|
52
|
+
case 'customer.subscription.deleted':
|
|
53
|
+
{
|
|
54
|
+
const subscription = event.data.object as Stripe.Subscription;
|
|
55
|
+
console.log('Subscription deleted:', subscription.id);
|
|
56
|
+
// Cancel user's subscription in DB
|
|
57
|
+
}
|
|
58
|
+
break;
|
|
39
59
|
}
|
|
40
60
|
|
|
41
61
|
return { received: true };
|
|
42
62
|
}
|
|
43
|
-
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Injectable, OnModuleInit, INestApplication } from '@nestjs/common';
|
|
2
|
+
import { PrismaClient } from '@prisma/client';
|
|
3
|
+
|
|
4
|
+
@Injectable()
|
|
5
|
+
export class PrismaService extends PrismaClient implements OnModuleInit {
|
|
6
|
+
async onModuleInit() {
|
|
7
|
+
await this.$connect();
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
async enableShutdownHooks(app: INestApplication) {
|
|
11
|
+
this.$on('beforeExit', async () => {
|
|
12
|
+
await app.close();
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -1,32 +1,45 @@
|
|
|
1
|
-
import { Injectable } from '@nestjs/common';
|
|
1
|
+
import { Injectable, NotFoundException } from '@nestjs/common';
|
|
2
|
+
import { PrismaService } from '../prisma/prisma.service';
|
|
2
3
|
import { CreateItemDto } from '../models/create-item.dto';
|
|
3
|
-
import { Item } from '../models/item.model';
|
|
4
|
-
import { v4 as uuidv4 } from 'uuid';
|
|
5
4
|
|
|
6
5
|
@Injectable()
|
|
7
6
|
export class ItemsService {
|
|
8
|
-
private
|
|
7
|
+
constructor(private prisma: PrismaService) {}
|
|
9
8
|
|
|
10
|
-
findAll()
|
|
11
|
-
return
|
|
9
|
+
async findAll() {
|
|
10
|
+
return this.prisma.item.findMany();
|
|
12
11
|
}
|
|
13
12
|
|
|
14
|
-
findOne(id: string)
|
|
15
|
-
|
|
13
|
+
async findOne(id: string) {
|
|
14
|
+
const item = await this.prisma.item.findUnique({
|
|
15
|
+
where: { id },
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
if (!item) {
|
|
19
|
+
throw new NotFoundException('Item not found');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return item;
|
|
16
23
|
}
|
|
17
24
|
|
|
18
|
-
create(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return item;
|
|
25
|
+
async create(createItemDto: CreateItemDto) {
|
|
26
|
+
return this.prisma.item.create({
|
|
27
|
+
data: {
|
|
28
|
+
name: createItemDto.name,
|
|
29
|
+
description: createItemDto.description,
|
|
30
|
+
price: createItemDto.price,
|
|
31
|
+
},
|
|
32
|
+
});
|
|
27
33
|
}
|
|
28
34
|
|
|
29
|
-
remove(id: string)
|
|
30
|
-
|
|
35
|
+
async remove(id: string) {
|
|
36
|
+
try {
|
|
37
|
+
await this.prisma.item.delete({
|
|
38
|
+
where: { id },
|
|
39
|
+
});
|
|
40
|
+
return true;
|
|
41
|
+
} catch (error) {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
31
44
|
}
|
|
32
|
-
}
|
|
45
|
+
}
|
|
@@ -5,9 +5,13 @@ terraform {
|
|
|
5
5
|
|
|
6
6
|
required_providers {
|
|
7
7
|
aws = {
|
|
8
|
-
source
|
|
8
|
+
source = "hashicorp/aws"
|
|
9
9
|
version = "~> 5.0"
|
|
10
10
|
}
|
|
11
|
+
random = {
|
|
12
|
+
source = "hashicorp/random"
|
|
13
|
+
version = "~> 3.5"
|
|
14
|
+
}
|
|
11
15
|
}
|
|
12
16
|
|
|
13
17
|
# Uncomment for remote state (recommended for production)
|
|
@@ -27,27 +31,27 @@ provider "aws" {
|
|
|
27
31
|
# Variables
|
|
28
32
|
variable "aws_region" {
|
|
29
33
|
description = "AWS region"
|
|
30
|
-
type
|
|
31
|
-
default
|
|
34
|
+
type = string
|
|
35
|
+
default = "us-east-1"
|
|
32
36
|
}
|
|
33
37
|
|
|
34
38
|
variable "environment" {
|
|
35
39
|
description = "Environment name (dev, staging, prod)"
|
|
36
|
-
type
|
|
37
|
-
default
|
|
40
|
+
type = string
|
|
41
|
+
default = "dev"
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
variable "app_name" {
|
|
41
45
|
description = "Application name"
|
|
42
|
-
type
|
|
43
|
-
default
|
|
46
|
+
type = string
|
|
47
|
+
default = "{{projectNameKebabCase}}"
|
|
44
48
|
}
|
|
45
49
|
|
|
46
50
|
# VPC
|
|
47
51
|
module "vpc" {
|
|
48
52
|
source = "./modules/vpc"
|
|
49
53
|
|
|
50
|
-
app_name
|
|
54
|
+
app_name = var.app_name
|
|
51
55
|
environment = var.environment
|
|
52
56
|
}
|
|
53
57
|
|
|
@@ -55,29 +59,49 @@ module "vpc" {
|
|
|
55
59
|
module "ecs" {
|
|
56
60
|
source = "./modules/ecs"
|
|
57
61
|
|
|
58
|
-
app_name
|
|
59
|
-
environment
|
|
60
|
-
vpc_id
|
|
61
|
-
|
|
62
|
+
app_name = var.app_name
|
|
63
|
+
environment = var.environment
|
|
64
|
+
vpc_id = module.vpc.vpc_id
|
|
65
|
+
public_subnet_ids = module.vpc.public_subnet_ids
|
|
66
|
+
private_subnet_ids = module.vpc.private_subnet_ids
|
|
67
|
+
alb_security_group_id = module.vpc.alb_security_group_id
|
|
68
|
+
ecs_tasks_security_group_id = module.vpc.ecs_tasks_security_group_id
|
|
62
69
|
}
|
|
63
70
|
|
|
64
71
|
# RDS PostgreSQL
|
|
65
72
|
module "rds" {
|
|
66
73
|
source = "./modules/rds"
|
|
67
74
|
|
|
68
|
-
app_name
|
|
69
|
-
environment
|
|
70
|
-
vpc_id
|
|
71
|
-
subnet_ids
|
|
75
|
+
app_name = var.app_name
|
|
76
|
+
environment = var.environment
|
|
77
|
+
vpc_id = module.vpc.vpc_id
|
|
78
|
+
subnet_ids = module.vpc.private_subnet_ids
|
|
72
79
|
security_group_id = module.vpc.db_security_group_id
|
|
73
80
|
}
|
|
74
81
|
|
|
75
82
|
# Outputs
|
|
83
|
+
output "vpc_id" {
|
|
84
|
+
value = module.vpc.vpc_id
|
|
85
|
+
}
|
|
86
|
+
|
|
76
87
|
output "ecs_cluster_name" {
|
|
77
88
|
value = module.ecs.cluster_name
|
|
78
89
|
}
|
|
79
90
|
|
|
91
|
+
output "ecr_repository_url" {
|
|
92
|
+
value = module.ecs.ecr_repository_url
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
output "alb_dns_name" {
|
|
96
|
+
value = module.ecs.alb_dns_name
|
|
97
|
+
description = "The DNS name of the ALB to access the application"
|
|
98
|
+
}
|
|
99
|
+
|
|
80
100
|
output "rds_endpoint" {
|
|
81
|
-
value
|
|
101
|
+
value = module.rds.endpoint
|
|
82
102
|
sensitive = true
|
|
83
|
-
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
output "db_name" {
|
|
106
|
+
value = module.rds.db_name
|
|
107
|
+
}
|