Skip to content

Commit f490a5f

Browse files
authored
Merge pull request #94 from EzeanoroEbuka/main
Logging service has been implemented and is saving to prisma database
2 parents 5b10da1 + c230fba commit f490a5f

File tree

19 files changed

+518
-90
lines changed

19 files changed

+518
-90
lines changed

Dockerfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,17 @@ FROM node:20-alpine
2525
WORKDIR /app
2626

2727
COPY package*.json ./
28-
RUN npm install
28+
RUN npm config set registry https://registry.npmjs.org/ && \
29+
npm ci --prefer-offline || npm install --fetch-retry-mintimeout 20000 \
30+
--fetch-retry-maxtimeout 120000 \
31+
--fetch-retries 5
2932

3033
COPY . .
3134

3235
# Generate Prisma client
3336
RUN npx prisma generate
3437

35-
EXPOSE 3000
38+
EXPOSE 3001
3639

3740
# CMD ["sh", "-c", "npx prisma migrate deploy && npm run start:dev"]
3841
CMD ["npm", "run", "start:dev"]

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ services:
55
context: .
66
dockerfile: Dockerfile
77
ports:
8-
- "3000:3000"
8+
- "3001:3001"
99
- "5555:5555"
1010
volumes:
1111
- .:/app
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-- CreateEnum
2+
CREATE TYPE "LogLevel" AS ENUM ('INFO', 'WARN', 'ERROR');
3+
4+
-- CreateTable
5+
CREATE TABLE "AppLog" (
6+
"id" TEXT NOT NULL,
7+
"level" "LogLevel" NOT NULL,
8+
"action" TEXT NOT NULL,
9+
"message" TEXT NOT NULL,
10+
"userId" TEXT,
11+
"metadata" JSONB,
12+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
13+
14+
CONSTRAINT "AppLog_pkey" PRIMARY KEY ("id")
15+
);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
Warnings:
3+
4+
- You are about to drop the column `gender` on the `pets` table. All the data in the column will be lost.
5+
- You are about to drop the column `size` on the `pets` table. All the data in the column will be lost.
6+
- You are about to drop the `documents` table. If the table is not empty, all the data it contains will be lost.
7+
8+
*/
9+
-- DropForeignKey
10+
ALTER TABLE "documents" DROP CONSTRAINT "documents_adoption_id_fkey";
11+
12+
-- DropForeignKey
13+
ALTER TABLE "documents" DROP CONSTRAINT "documents_uploaded_by_id_fkey";
14+
15+
-- AlterTable
16+
ALTER TABLE "pets" DROP COLUMN "gender",
17+
DROP COLUMN "size";
18+
19+
-- DropTable
20+
DROP TABLE "documents";
21+
22+
-- DropEnum
23+
DROP TYPE "PetGender";
24+
25+
-- DropEnum
26+
DROP TYPE "PetSize";
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
-- CreateTable
2+
CREATE TABLE "Document" (
3+
"id" TEXT NOT NULL,
4+
"fileName" TEXT NOT NULL,
5+
"fileUrl" TEXT NOT NULL,
6+
"publicId" TEXT NOT NULL,
7+
"mimeType" TEXT NOT NULL,
8+
"size" INTEGER NOT NULL,
9+
"uploadedById" TEXT NOT NULL,
10+
"adoptionId" TEXT NOT NULL,
11+
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
12+
"updatedAt" TIMESTAMP(3) NOT NULL,
13+
14+
CONSTRAINT "Document_pkey" PRIMARY KEY ("id")
15+
);
16+
17+
-- AddForeignKey
18+
ALTER TABLE "Document" ADD CONSTRAINT "Document_uploadedById_fkey" FOREIGN KEY ("uploadedById") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
19+
20+
-- AddForeignKey
21+
ALTER TABLE "Document" ADD CONSTRAINT "Document_adoptionId_fkey" FOREIGN KEY ("adoptionId") REFERENCES "adoptions"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

prisma/schema.prisma

Lines changed: 71 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
generator client {
23
provider = "prisma-client-js"
34
}
@@ -22,6 +23,9 @@ enum PetSpecies {
2223
OTHER
2324
}
2425

26+
27+
28+
2529
enum AdoptionStatus {
2630
REQUESTED
2731
PENDING
@@ -32,12 +36,13 @@ enum AdoptionStatus {
3236
CANCELLED
3337
}
3438

39+
3540
enum CustodyStatus {
36-
PENDING
3741
ACTIVE
3842
RETURNED
3943
CANCELLED
4044
VIOLATION
45+
PENDING
4146
}
4247

4348
enum CustodyType {
@@ -46,6 +51,8 @@ enum CustodyType {
4651
SHELTER
4752
}
4853

54+
55+
4956
enum EscrowStatus {
5057
CREATED
5158
FUNDED
@@ -54,6 +61,7 @@ enum EscrowStatus {
5461
DISPUTED
5562
}
5663

64+
5765
enum EventEntityType {
5866
USER
5967
PET
@@ -62,6 +70,7 @@ enum EventEntityType {
6270
ESCROW
6371
}
6472

73+
6574
enum EventType {
6675
USER_REGISTERED
6776
PET_REGISTERED
@@ -76,17 +85,11 @@ enum EventType {
7685
TRUST_SCORE_UPDATED
7786
}
7887

79-
enum PetGender {
80-
MALE
81-
FEMALE
82-
}
83-
84-
enum PetSize {
85-
SMALL
86-
MEDIUM
87-
LARGE
88+
enum LogLevel {
89+
INFO
90+
WARN
91+
ERROR
8892
}
89-
9093
// ─── Models ──────────────────────────────────────────────
9194

9295
model User {
@@ -97,41 +100,41 @@ model User {
97100
lastName String @map("last_name")
98101
role UserRole @default(USER)
99102
100-
trustScore Float @default(50)
103+
trustScore Float @default(50)
101104
102105
stellarPublicKey String? @unique @map("stellar_public_key")
103106
avatarUrl String? @map("avatar_url")
104107
105108
createdAt DateTime @default(now()) @map("created_at")
106109
updatedAt DateTime @updatedAt @map("updated_at")
107110
108-
petsOwned Pet[] @relation("PetOwner")
111+
petsOwned Pet[] @relation("PetOwner")
109112
110113
adoptionsAsAdopter Adoption[] @relation("Adopter")
111114
adoptionsAsOwner Adoption[] @relation("Owner")
112115
113116
custodiesHeld Custody[] @relation("CustodyHolder")
114117
115-
events EventLog[] @relation("ActorEvents")
118+
events EventLog[] @relation("ActorEvents")
119+
116120
documents Document[]
117121
118122
@@map("users")
119123
}
120124

125+
126+
121127
model Pet {
122-
id String @id @default(uuid())
128+
id String @id @default(uuid())
123129
name String
124130
species PetSpecies
125131
breed String?
126132
age Int?
127133
description String?
128-
imageUrl String? @map("image_url")
134+
imageUrl String? @map("image_url")
129135
130-
gender PetGender? // Optional gender field
131-
size PetSize? // Optional size field
132-
133-
currentOwnerId String? @map("current_owner_id")
134-
currentOwner User? @relation("PetOwner", fields: [currentOwnerId], references: [id])
136+
currentOwnerId String? @map("current_owner_id")
137+
currentOwner User? @relation("PetOwner", fields: [currentOwnerId], references: [id])
135138
136139
createdAt DateTime @default(now()) @map("created_at")
137140
updatedAt DateTime @updatedAt @map("updated_at")
@@ -144,6 +147,7 @@ model Pet {
144147
@@map("pets")
145148
}
146149

150+
147151
model Adoption {
148152
id String @id @default(uuid())
149153
status AdoptionStatus @default(REQUESTED)
@@ -158,27 +162,29 @@ model Adoption {
158162
ownerId String @map("owner_id")
159163
owner User @relation("Owner", fields: [ownerId], references: [id])
160164
161-
escrowId String? @unique @map("escrow_id")
165+
escrowId String? @unique @map("escrow_id")
162166
escrow Escrow? @relation(fields: [escrowId], references: [id])
163-
164-
createdAt DateTime @default(now()) @map("created_at")
165-
updatedAt DateTime @updatedAt @map("updated_at")
167+
166168
documents Document[]
169+
createdAt DateTime @default(now()) @map("created_at")
170+
updatedAt DateTime @updatedAt @map("updated_at")
167171
168172
@@index([status])
169173
@@index([adopterId])
170174
@@index([ownerId])
171175
@@map("adoptions")
172176
}
173177

178+
179+
174180
model Custody {
175-
id String @id @default(uuid())
176-
status CustodyStatus @default(ACTIVE)
177-
type CustodyType
181+
id String @id @default(uuid())
182+
status CustodyStatus @default(ACTIVE)
183+
type CustodyType
178184
179185
depositAmount Decimal? @db.Decimal(12, 2)
180186
181-
startDate DateTime @map("start_date")
187+
startDate DateTime @map("start_date")
182188
endDate DateTime?
183189
184190
petId String @map("pet_id")
@@ -198,20 +204,21 @@ model Custody {
198204
@@map("custodies")
199205
}
200206

207+
201208
model Escrow {
202209
id String @id @default(uuid())
203210
204-
stellarPublicKey String @unique @map("stellar_public_key")
211+
stellarPublicKey String @unique @map("stellar_public_key")
205212
stellarSecretEncrypted String @map("stellar_secret_encrypted")
206213
207-
assetCode String @default("XLM") @map("asset_code")
214+
assetCode String @default("XLM") @map("asset_code")
208215
assetIssuer String? @map("asset_issuer")
209216
210217
amount Decimal @db.Decimal(12, 2)
211218
212-
fundingTxHash String? @map("funding_tx_hash")
213-
releaseTxHash String? @map("release_tx_hash")
214-
refundTxHash String? @map("refund_tx_hash")
219+
fundingTxHash String? @map("funding_tx_hash")
220+
releaseTxHash String? @map("release_tx_hash")
221+
refundTxHash String? @map("refund_tx_hash")
215222
216223
requiredSignatures Int @default(2)
217224
@@ -227,11 +234,23 @@ model Escrow {
227234
@@map("escrows")
228235
}
229236

237+
238+
model AppLog {
239+
id String @id @default(uuid())
240+
level LogLevel
241+
action String
242+
message String
243+
userId String?
244+
metadata Json?
245+
createdAt DateTime @default(now())
246+
}
247+
248+
230249
model EventLog {
231-
id String @id @default(uuid())
232-
entityType EventEntityType @map("entity_type")
233-
entityId String @map("entity_id")
234-
eventType EventType @map("event_type")
250+
id String @id @default(uuid())
251+
entityType EventEntityType @map("entity_type")
252+
entityId String @map("entity_id")
253+
eventType EventType @map("event_type")
235254
236255
actorId String? @map("actor_id")
237256
actor User? @relation("ActorEvents", fields: [actorId], references: [id])
@@ -251,22 +270,18 @@ model EventLog {
251270
}
252271

253272
model Document {
254-
id String @id @default(uuid())
255-
fileName String @map("file_name")
256-
fileUrl String @map("file_url")
257-
publicId String @map("public_id")
258-
mimeType String @map("mime_type")
259-
size Int
260-
261-
uploadedById String @map("uploaded_by_id")
262-
uploadedBy User @relation(fields: [uploadedById], references: [id], onDelete: Cascade)
263-
264-
adoptionId String? @map("adoption_id")
265-
adoption Adoption? @relation(fields: [adoptionId], references: [id], onDelete: Cascade)
266-
267-
createdAt DateTime @default(now()) @map("created_at")
268-
269-
@@index([uploadedById])
270-
@@index([adoptionId])
271-
@@map("documents")
273+
id String @id @default(cuid())
274+
fileName String
275+
fileUrl String
276+
publicId String
277+
mimeType String
278+
size Int
279+
uploadedById String
280+
adoptionId String
281+
createdAt DateTime @default(now())
282+
updatedAt DateTime @updatedAt
283+
284+
uploadedBy User @relation(fields: [uploadedById], references: [id])
285+
adoption Adoption @relation(fields: [adoptionId], references: [id])
272286
}
287+

src/app.module.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ import { EventsModule } from './events/events.module';
1111
import { StellarModule } from './stellar/stellar.module';
1212
import { AuthModule } from './auth/auth.module';
1313
import { HealthModule } from './health/health.module';
14-
import { CloudinaryModule } from './cloudinary/cloudinary.module';
15-
import { UsersModule } from './users/users.module';
16-
import { EmailModule } from './email/email.module';
14+
import { LoggingModule } from './logging/logging.module';
15+
import { HttpExceptionFilter } from './common/filters/http-exception.filter';
16+
import { APP_INTERCEPTOR } from '@nestjs/core';
17+
import { LoggingInterceptor } from './logging/logging.interceptor';
1718

1819
@Module({
1920
imports: [
@@ -27,11 +28,18 @@ import { EmailModule } from './email/email.module';
2728
StellarModule,
2829
AuthModule,
2930
HealthModule,
30-
CloudinaryModule,
31-
UsersModule,
32-
EmailModule,
31+
LoggingModule,
32+
3333
],
34+
3435
controllers: [AppController],
35-
providers: [AppService],
36+
providers: [
37+
{
38+
provide: APP_INTERCEPTOR,
39+
useClass: LoggingInterceptor,
40+
},
41+
AppService, HttpExceptionFilter],
42+
3643
})
37-
export class AppModule {}
44+
45+
export class AppModule { }

0 commit comments

Comments
 (0)