Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { ManufacturerModule } from './foodManufacturers/manufacturer.module';
import { DonationModule } from './donations/donations.module';
import { DonationItemsModule } from './donationItems/donationItems.module';
import { AllocationModule } from './allocations/allocations.module';
import { ScheduleModule } from '@nestjs/schedule';

@Module({
imports: [
Expand All @@ -29,6 +30,7 @@ import { AllocationModule } from './allocations/allocations.module';
useFactory: async (configService: ConfigService) =>
configService.get('typeorm'),
}),
ScheduleModule.forRoot(),
UsersModule,
AuthModule,
PantriesModule,
Expand Down
8 changes: 7 additions & 1 deletion apps/backend/src/donations/donations.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,19 @@ import { DonationService } from './donations.service';
import { DonationsController } from './donations.controller';
import { ManufacturerModule } from '../foodManufacturers/manufacturer.module';
import { FoodManufacturer } from '../foodManufacturers/manufacturer.entity';
import { DonationsSchedulerService } from './donations.scheduler';

@Module({
imports: [
TypeOrmModule.forFeature([Donation, FoodManufacturer]),
ManufacturerModule,
],
controllers: [DonationsController],
providers: [DonationService, AuthService, JwtStrategy],
providers: [
DonationService,
AuthService,
JwtStrategy,
DonationsSchedulerService,
],
})
export class DonationModule {}
16 changes: 16 additions & 0 deletions apps/backend/src/donations/donations.scheduler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Injectable, Logger } from '@nestjs/common';
import { DonationService } from './donations.service';
import { Cron } from '@nestjs/schedule';

@Injectable()
export class DonationsSchedulerService {
private readonly logger = new Logger(DonationsSchedulerService.name);

constructor(private readonly donationService: DonationService) {}

@Cron('0 9 * * *') // Runs every day at 9 AM
async handleDailyRecurringDonations() {
this.logger.log('Running daily donation reminder cron job');
await this.donationService.handleRecurringDonations();
}
}
5 changes: 5 additions & 0 deletions apps/backend/src/donations/donations.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,9 @@ export class DonationService {
donation.status = DonationStatus.FULFILLED;
return this.repo.save(donation);
}

async handleRecurringDonations(): Promise<void> {
console.log('Accessing donation service from cron job');
// TODO: Implement logic for sending reminder emails
}
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"@nestjs/core": "^10.0.2",
"@nestjs/passport": "^10.0.2",
"@nestjs/platform-express": "^10.0.2",
"@nestjs/schedule": "^6.1.0",
"@nestjs/swagger": "^7.4.2",
"@nestjs/typeorm": "^10.0.0",
"@types/google-libphonenumber": "^7.4.30",
Expand Down
Loading
Loading