Browse Source

biometrics setup

Dr-Swopt 6 months ago
parent
commit
c7edf83fd3

+ 2 - 1
src/app.module.ts

@@ -4,9 +4,10 @@ import { GeneralService } from './services/general.service';
 import { AuthModule } from './auth/auth.module';
 import { AttendanceModule } from './attendance/attendance.module';
 import { SocketGateway } from './gateway/socket.gateway';
+import { PaymentModule } from './payment/payment.module';
 
 @Module({
-  imports: [AuthModule, AttendanceModule, SocketGateway],
+  imports: [AuthModule, AttendanceModule, PaymentModule, SocketGateway],
   controllers: [AppController],
   providers: [GeneralService],
 })

+ 1 - 1
src/attendance/attendance.controller.ts

@@ -27,7 +27,7 @@ export class AttendanceController {
     ) {
         const user = req.user; // ← comes from the token
         const { date } = body;
-        this.service.emit({ name: user.name, date: date })
+        this.service.emit({ name: user.name, date: body.date })
         return {
             message: `Attendance received for ${user.name} on ${new Date(date).toDateString()}`,
             user: {

+ 2 - 1
src/attendance/attendance.module.ts

@@ -1,10 +1,11 @@
 import { Module } from '@nestjs/common';
 import { AttendanceController } from './attendance.controller';
 import { AttendanceService } from 'src/services/attendance.service';
+import { SocketGateway } from 'src/gateway/socket.gateway';
 
 @Module({
   controllers: [AttendanceController],
   exports: [], // if you have services to share with other modules
-  providers: [AttendanceService]
+  providers: [AttendanceService, SocketGateway]
 })
 export class AttendanceModule {}

+ 1 - 1
src/config.ts

@@ -1,3 +1,3 @@
 export const serverConfig = {
-    exposedUrl: `https://a19f-60-53-251-228.ngrok-free.app`
+    exposedUrl: `https://a654-124-13-232-72.ngrok-free.app`
 }

+ 1 - 1
src/gateway/socket.gateway.ts

@@ -22,7 +22,7 @@ export class SocketGateway implements OnGatewayConnection, OnGatewayDisconnect {
     }
 
     emit(message: any) {
-        this.messageResponseSubject.next(message)
+        this.server.emit(`message`, message)
     }
 
     // Emit latest changes to UI. Just one way street for now

+ 2 - 3
src/payment/payment.controller.ts

@@ -21,14 +21,13 @@ export class PaymentController {
 
     @UseGuards(JwtAuthGuard)
     @Post()
-    submitAttendance(
+    submitPayment(
         @Request() req,
         @Body() body: PaymentPayload
     ) {
         const user = req.user; // ← comes from the token
         const { date } = body;
-        this.service.emit({ name: user.name, date: date, verified: body.verified})
-
+        this.service.emit({ name: user.name, date: body.date, verified: body.verified })
         return {
             message: `Payment received for ${user.name} on ${new Date(date).toDateString()}`,
             user: {

+ 2 - 1
src/payment/payment.module.ts

@@ -1,10 +1,11 @@
 import { Module } from '@nestjs/common';
 import { PaymentController } from './payment.controller';
 import { PaymentService } from 'src/services/payment.service';
+import { SocketGateway } from 'src/gateway/socket.gateway';
 
 @Module({
   controllers: [PaymentController],
   exports: [], // if you have services to share with other modules
-  providers: [PaymentService]
+  providers: [PaymentService, SocketGateway]
 })
 export class PaymentModule {}

+ 4 - 2
src/services/attendance.service.ts

@@ -1,15 +1,17 @@
 import { Injectable } from '@nestjs/common';
+import { SocketGateway } from 'src/gateway/socket.gateway';
 import { AttendancePayload } from 'src/interface/interface';
 
 @Injectable()
 export class AttendanceService {
     attendanceRecord: AttendancePayload[] = []
-    constructor() {
-        // need to pipe the socket obs here so that the value can be updated to UI in real time
+
+    constructor(private socket: SocketGateway) {
     }
 
     public emit(attendance: AttendancePayload) {
         console.log(`Processing attendance for ${attendance.name} at ${attendance.date}`)
         this.attendanceRecord.push(attendance)
+        this.socket.emit({ action: `Attendance`, name: attendance.name, time: attendance.date })
     }
 }

+ 3 - 2
src/services/payment.service.ts

@@ -1,15 +1,16 @@
 import { Injectable } from '@nestjs/common';
+import { SocketGateway } from 'src/gateway/socket.gateway';
 import { AttendancePayload, PaymentPayload } from 'src/interface/interface';
 
 @Injectable()
 export class PaymentService {
     paymentRecord: PaymentPayload[] = []
-    constructor() {
-        // need to pipe the socket obs here so that the value can be updated to UI in real time
+    constructor(private socket: SocketGateway) {
     }
 
     public emit(payment: PaymentPayload) {
         console.log(`Processing payment for ${payment.name} at ${payment.date}`)
         this.paymentRecord.push(payment)
+        this.socket.emit({ action: `Payment`, name: payment.name, time: payment.date })
     }
 }