Skip to content

Commit 59076ff

Browse files
committed
feat: added tx to wagers column
1 parent 5109b4a commit 59076ff

File tree

10 files changed

+61
-33
lines changed

10 files changed

+61
-33
lines changed

backend/.env.example

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,36 @@
11
# GENERAL CONFIG
2+
DB_SYNCHRONIZE=true
23
NODE_ENV=development
3-
SERVER_PORT=8080
4+
PORT=8080
45

56
# JWT CONFIG
6-
JWT_SECRET=
7-
REFRESH_TOKEN_SECRET=
7+
JWT_SECRET=superhotsecret
8+
REFRESH_TOKEN_SECRET=MYREFRESHTOKENSECRET
89
JWT_ACCESS_EXPIRTY_TIME='15m'
910
JWT_REFRESH_EXPIRTY_TIME='7d'
1011
JWT_INVITATION_EXPIRY_TIME='24h'
1112

1213
# REDIS CONFIG
13-
REDIS_HOST=
14-
REDIS_PORT=
15-
REDIS_PASSWORD=
16-
REDIS_USERNAME=
14+
REDIS_HOST=redis-cache
15+
REDIS_PORT=6379
16+
REDIS_PASSWORD=mystrongpassword
17+
REDIS_USERNAME=default
1718

1819
# OTP CONFIG
1920
OTP_SECRET=
2021

2122
# SENDGRID CONFIG
22-
SEND_GRID_HOST=
23-
SENDGRID_API_KEY=
24-
SEND_GRID_MAIL_FROM=
25-
SEND_GRID_PSD=
26-
SEND_GRID_USERNAME=
23+
SEND_GRID_HOST=dsdd
24+
SENDGRID_API_KEY=sddd
25+
SEND_GRID_MAIL_FROM=dsdd
26+
SEND_GRID_PSD=sddd
27+
SEND_GRID_USERNAME=sdddd
2728

2829
# POSTGRES DB CONFIG
29-
POSTGRES_USER=postgres ## DATABASE USERNAME
30-
POSTGRES_PASSWORD=strongpassword ## DATABASE PASSWORD
31-
POSTGRES_DB_NAME=starkwager-backend_db ## DATABASE NAME / DOCKER CONTAINER NAME
32-
POSTGRES_DB_SCHEMA=wager ## POSTGRES SCHEMA NAME
30+
POSTGRES_USER=postgres
31+
POSTGRES_PASSWORD=strongpassword
32+
POSTGRES_DB_NAME=postgres_db
33+
POSTGRES_DB_SCHEMA=wager
3334

3435
## Use this when running on docker container.
3536
POSTGRES_DB_HOST=${POSTGRES_DB_NAME}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-- AlterTable
2+
ALTER TABLE "wagers" ADD COLUMN "tx_hash" TEXT,
3+
ADD COLUMN "tx_status" TEXT;

backend/prisma/schema.prisma

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ model Wager {
3636
createdAt DateTime @default(now()) @map("created_at")
3737
updatedAt DateTime @updatedAt @map("updated_at")
3838
39+
txHash String? @map("tx_hash") // NEW: Transaction hash
40+
txStatus String? @map("tx_status") // NEW: "pending", "confirmed", "failed"
41+
3942
// Relationships
4043
category Category @relation(fields: [categoryId], references: [id])
4144
createdBy User @relation(fields: [createdById], references: [id])

backend/src/wager/dtos/wager.dto.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ enum WagerStatus {
1515
ACTIVE = 'active',
1616
COMPLETED = 'completed',
1717
}
18+
19+
export enum TxStatus {
20+
PENDING = 'pending',
21+
CONFIRMED = 'confirmed',
22+
FAILED = 'failed',
23+
}
1824
export default WagerStatus;
1925

2026
export class CreateWagerDto {
@@ -45,6 +51,13 @@ export class CreateWagerDto {
4551
@IsOptional()
4652
createdById: string;
4753

54+
@IsString()
55+
txHash: string;
56+
57+
@IsString()
58+
@IsEnum(TxStatus)
59+
txStatus: string;
60+
4861
@IsOptional()
4962
@IsString({ each: true })
5063
hashtags?: string[];

backend/src/wager/services/wager.service.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,32 +76,38 @@ export class WagerService {
7676
async bulkCreateWagers(payload: CreateWagerDto[]) {
7777
return this.prisma.$transaction(async (tx) => {
7878
const createdWagers = [];
79-
79+
8080
for (const wager of payload) {
8181
// Check if a wager with the same name already exists
8282
const existingWager = await tx.wager.findFirst({
8383
where: { name: wager.name },
8484
});
85-
85+
8686
if (existingWager) {
87-
throw new BadRequestException(`Wager with name "${wager.name}" already exists.`);
87+
throw new BadRequestException(
88+
`Wager with name "${wager.name}" already exists.`,
89+
);
8890
}
89-
91+
9092
// Create the wager
9193
const newWager = await tx.wager.create({
9294
data: {
9395
...wager,
9496
hashtags: wager.hashtags
95-
? { connectOrCreate: wager.hashtags.map((name) => ({ where: { name }, create: { name } })) }
97+
? {
98+
connectOrCreate: wager.hashtags.map((name) => ({
99+
where: { name },
100+
create: { name },
101+
})),
102+
}
96103
: undefined,
97104
},
98105
});
99-
106+
100107
createdWagers.push(newWager);
101108
}
102-
109+
103110
return createdWagers;
104111
});
105112
}
106-
107113
}

backend/src/websocket/websocket.gateway.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,4 @@ describe('WebsocketGateway', () => {
8585
expect(mockSocket.emit).toHaveBeenCalledWith('leftRoom', { room });
8686
});
8787
});
88-
});
88+
});

backend/src/websocket/websocket.gateway.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ export class WebsocketGateway
4141

4242
@SubscribeMessage('message')
4343
handleMessage(client: Socket, payload: any): void {
44-
this.logger.log(`Received message from ${client.id}: ${JSON.stringify(payload)}`);
44+
this.logger.log(
45+
`Received message from ${client.id}: ${JSON.stringify(payload)}`,
46+
);
4547
// Broadcast the message to all connected clients except the sender
4648
client.broadcast.emit('message', {
4749
senderId: client.id,

backend/src/websocket/websocket.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ import { WebsocketService } from './websocket.service';
66
providers: [WebsocketGateway, WebsocketService],
77
exports: [WebsocketService],
88
})
9-
export class WebsocketModule {}
9+
export class WebsocketModule {}

backend/src/websocket/websocket.service.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ describe('WebsocketService', () => {
5252
it('should broadcast to all connected clients', () => {
5353
const event = 'test-event';
5454
const payload = { message: 'test message' };
55-
55+
5656
service.handleConnection(mockSocket);
5757
service.broadcastToAll(event, payload);
58-
58+
5959
expect(mockSocket.emit).toHaveBeenCalledWith(event, payload);
6060
});
6161
});
@@ -65,11 +65,11 @@ describe('WebsocketService', () => {
6565
const room = 'test-room';
6666
const event = 'test-event';
6767
const payload = { message: 'test message' };
68-
68+
6969
service.handleConnection(mockSocket);
7070
service.broadcastToRoom(room, event, payload);
71-
71+
7272
expect(mockSocket.emit).toHaveBeenCalledWith(event, payload);
7373
});
7474
});
75-
});
75+
});

backend/src/websocket/websocket.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ export class WebsocketService {
3333
}
3434
});
3535
}
36-
}
36+
}

0 commit comments

Comments
 (0)