Skip to content

Commit 8a6a8cd

Browse files
authored
Merge pull request #168 from cuappdev/ashley/fixing-dev
Fixing Dev
2 parents 9cdc478 + be0bd16 commit 8a6a8cd

5 files changed

Lines changed: 63 additions & 121 deletions

File tree

src/api/controllers/NotifController.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Body, CurrentUser, Delete, Get, JsonController, Param, Params, Post } from 'routing-controllers';
2-
import { FindTokensRequest, DiscountNotificationRequest, RequestMatchNotificationRequest } from 'src/types';
2+
import { FindTokensRequest, DiscountNotificationRequest, RequestMatchNotificationRequest } from '../../types';
33
import { NotifService } from '../../services/NotifService';
44
import { UserModel } from '../../models/UserModel';
55

@@ -67,20 +67,20 @@ export class NotifController {
6767
* Send a transaction confirmation notification to the buyer
6868
* POST /notif/transaction-confirmation/:transactionId
6969
*/
70-
@Post('transaction-confirmation/:transactionId')
71-
async sendTransactionConfirmation(
72-
@Param('transactionId') transactionId: string
73-
) {
74-
return this.notifService.sendTransactionConfirmationNotification(transactionId);
75-
}
70+
// @Post('transaction-confirmation/:transactionId')
71+
// async sendTransactionConfirmation(
72+
// @Param('transactionId') transactionId: string
73+
// ) {
74+
// return this.notifService.sendTransactionConfirmationNotification(transactionId);
75+
// }
7676

7777
/**
7878
* Check for and send all pending transaction confirmation notifications
7979
* This can be called by a cron job or manually for testing
8080
* POST /notif/check-pending-transactions
8181
*/
82-
@Post('check-pending-transactions')
83-
async checkPendingTransactions() {
84-
return this.notifService.sendPendingTransactionConfirmations();
85-
}
82+
// @Post('check-pending-transactions')
83+
// async checkPendingTransactions() {
84+
// return this.notifService.sendPendingTransactionConfirmations();
85+
// }
8686
}

src/app.ts

Lines changed: 22 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
// Load environment and Firebase configuration first
2-
import "dotenv/config";
2+
import dotenv from "dotenv";
3+
dotenv.config();
34
import "./firebase";
45
import "reflect-metadata";
56

67
import {
78
createExpressServer,
89
useContainer as routingUseContainer,
10+
ForbiddenError,
11+
HttpError,
12+
UnauthorizedError,
913
} from "routing-controllers";
1014
import { getManager, useContainer } from "typeorm";
1115
import { Container } from "typeorm-typedi-extensions";
1216
import { Express, Request, Response } from "express";
1317
import * as swaggerUi from "swagger-ui-express";
14-
import swaggerDocument from "../swagger.json";
18+
import * as path from "path";
19+
import { firebaseAdmin as admin } from "./firebase";
1520

1621
import { controllers } from './api/controllers';
1722
import { middlewares } from './api/middlewares';
@@ -22,48 +27,6 @@ import { ReportService } from './services/ReportService';
2227
import { reportToString } from './utils/Requests';
2328
import { startTransactionConfirmationCron } from './cron/transactionCron';
2429

25-
dotenv.config();
26-
27-
const port = process.env.PORT ?? 3000;
28-
const app: Express = createExpressServer({
29-
cors: true,
30-
routePrefix: "/api/",
31-
controllers: controllers,
32-
middlewares: middlewares,
33-
defaults: {
34-
paramOptions: {
35-
required: true, // Make all params required by default
36-
},
37-
},
38-
validation: true,
39-
development: process.env.NODE_ENV !== "production",
40-
defaultErrorHandler: false,
41-
currentUserChecker: FirebaseCurrentUserChecker,
42-
});
43-
44-
/**
45-
* Setup Swagger docs
46-
*/
47-
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument));
48-
console.log(
49-
`Swagger documentation available at http://localhost:${port}/api-docs`,
50-
);
51-
52-
/**
53-
* Health check endpoint
54-
*/
55-
app.get("/health", async (_req: Request, res: Response) => {
56-
const manager = getManager();
57-
try {
58-
await manager.query("SELECT 1");
59-
res.status(200).json({ status: "healthy", database: "Connected" });
60-
} catch (error) {
61-
res
62-
.status(500)
63-
.json({ status: "Error", database: "Not connected", error: error });
64-
}
65-
});
66-
6730
// Setup dependency injection containers
6831
routingUseContainer(Container);
6932
useContainer(Container);
@@ -175,6 +138,21 @@ async function main() {
175138
`Swagger documentation available at http://localhost:${port}/api-docs`,
176139
);
177140

141+
/**
142+
* Health check endpoint
143+
*/
144+
app.get("/health", async (_req: Request, res: Response) => {
145+
const manager = getManager();
146+
try {
147+
await manager.query("SELECT 1");
148+
res.status(200).json({ status: "healthy", database: "Connected" });
149+
} catch (error) {
150+
res
151+
.status(500)
152+
.json({ status: "Error", database: "Not connected", error: error });
153+
}
154+
});
155+
178156
const entityManager = getManager();
179157
const reportService = new ReportService(entityManager);
180158
const reportController = new ReportController(reportService);

src/cron/transactionCron.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import cron from 'node-cron';
1+
// import cron from 'node-cron';
22
import { getManager } from 'typeorm';
33
import { NotifService } from '../services/NotifService';
44

@@ -17,23 +17,23 @@ export function startTransactionConfirmationCron() {
1717
// * = every month
1818
// * = every day of week
1919

20-
cron.schedule('*/15 * * * *', async () => {
21-
console.log('[CRON] Checking for pending transaction confirmations...');
20+
// cron.schedule('*/15 * * * *', async () => {
21+
// console.log('[CRON] Checking for pending transaction confirmations...');
2222

23-
try {
24-
const entityManager = getManager();
25-
const notifService = new NotifService(entityManager);
23+
// try {
24+
// const entityManager = getManager();
25+
// const notifService = new NotifService(entityManager);
2626

27-
const result = await notifService.sendPendingTransactionConfirmations();
28-
console.log('[CRON] Transaction confirmation check complete:', result.message);
27+
// const result = await notifService.sendPendingTransactionConfirmations();
28+
// console.log('[CRON] Transaction confirmation check complete:', result.message);
2929

30-
if (result.results && result.results.length > 0) {
31-
console.log('[CRON] Notifications sent:', result.results);
32-
}
33-
} catch (error) {
34-
console.error('[CRON] Error checking pending transactions:', error);
35-
}
36-
});
30+
// if (result.results && result.results.length > 0) {
31+
// console.log('[CRON] Notifications sent:', result.results);
32+
// }
33+
// } catch (error) {
34+
// console.error('[CRON] Error checking pending transactions:', error);
35+
// }
36+
// });
3737

3838
console.log('[CRON] Transaction confirmation cron job started (runs every 15 minutes)');
3939
}

src/migrations/1767386999887-AddUserStats 2.ts

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

src/services/NotifService.ts

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,19 @@ import { NotificationData, FindTokensRequest, DiscountNotificationRequest, Reque
44
import Repositories, { TransactionsManager } from '../repositories';
55
import { EntityManager } from 'typeorm';
66
import { InjectManager } from 'typeorm-typedi-extensions';
7-
import { getMessaging, Message } from 'firebase-admin/messaging';
7+
import { firebaseAdmin } from '../firebase';
8+
9+
const getMessaging = () => firebaseAdmin.messaging();
10+
11+
// Message type from firebase-admin
12+
interface Message {
13+
notification?: {
14+
title?: string;
15+
body?: string;
16+
};
17+
data?: { [key: string]: string };
18+
token: string;
19+
}
820

921
interface NotifPayload {
1022
title: string;
@@ -140,20 +152,7 @@ export class NotifService {
140152
}
141153
});
142154
});
143-
await this.sendFCMNotifs(notifs, user.firebaseUid);
144-
return {
145-
message: "Notification sent successfully",
146-
httpCode: 200,
147-
};
148-
} catch (err) {
149-
console.log(err);
150-
return {
151-
message: "Notification not sent",
152-
httpCode: 500,
153-
};
154-
}
155-
});
156-
}
155+
}
157156

158157
public async sendRequestMatchNotification(request: RequestMatchNotificationRequest): Promise<NotifResult> {
159158
return this.transactions.readWrite(async (transactionalEntityManager) => {
@@ -192,20 +191,7 @@ export class NotifService {
192191
}
193192
});
194193
});
195-
await this.sendFCMNotifs(notifs, request.userId);
196-
return {
197-
message: "Notification sent successfully",
198-
httpCode: 200,
199-
};
200-
} catch (err) {
201-
console.log(err);
202-
return {
203-
message: "Notification not sent",
204-
httpCode: 500,
205-
};
206-
}
207-
});
208-
}
194+
}
209195

210196
public async getRecentNotifications(userId: string) {
211197
return this.transactions.readWrite(async (transactionalEntityManager) => {

0 commit comments

Comments
 (0)