Skip to content

Commit

Permalink
feat: cron
Browse files Browse the repository at this point in the history
  • Loading branch information
suk-6 committed Sep 28, 2024
1 parent c8c5b12 commit ad7b7e6
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"@nestjs/mapped-types": "*",
"@nestjs/passport": "^10.0.3",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/schedule": "^4.1.1",
"@nestjs/swagger": "^7.4.0",
"@nomicfoundation/hardhat-ignition": "^0.15.5",
"@nomicfoundation/hardhat-toolbox": "^5.0.0",
Expand Down
30 changes: 30 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/common/providers/schedule.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Module } from '@nestjs/common';
import { ScheduleModule } from '@nestjs/schedule';

@Module({
imports: [ScheduleModule.forRoot()],
})
export class SHOCKIScheduleModule {}
24 changes: 24 additions & 0 deletions src/modules/product/product.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
NotFoundException,
} from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { Cron, CronExpression } from '@nestjs/schedule';

import { PrismaService } from 'src/common/modules/prisma/prisma.service';
import { S3Service } from 'src/common/modules/s3/s3.service';
Expand Down Expand Up @@ -554,6 +555,29 @@ export class ProductService {
});
}

@Cron(CronExpression.EVERY_MINUTE)
async authSale() {
const users = await this.prisma.user.findMany({
select: {
id: true,
},
});
const products = await this.prisma.product.findMany({
select: {
id: true,
},
where: {
type: ProductType.FUNDING,
},
});

for (const user of users) {
for (const product of products) {
await this.saleProductToken(user.id, product.id);
}
}
}

async saleProductToken(userId: string, productId: string) {
const product = await this.prisma.product.findUnique({
select: {
Expand Down

0 comments on commit ad7b7e6

Please sign in to comment.