Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add importDate to donation entity #1263

Merged
merged 2 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 13 additions & 0 deletions migration/1706012712969-add_import_date_to_donation_entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { MigrationInterface, QueryRunner } from "typeorm";

export class addImportDateToDonationEntity1706012712969 implements MigrationInterface {

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "donation" ADD COLUMN "importDate" TIMESTAMP WITH TIME ZONE`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
await queryRunner.query(`ALTER TABLE "donation" ADD COLUMN "importDate" TIMESTAMP WITH TIME ZONE`);
await queryRunner.query(`ALTER TABLE "donation" ADD COLUMN IF NOT EXISTS "importDate" TIMESTAMP WITH TIME ZONE`);

}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "donation" DROP COLUMN "importDate"`);
}

}
4 changes: 4 additions & 0 deletions src/entities/donation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ export class Donation extends BaseEntity {
@Column()
createdAt: Date;

@Field(type => Date, { nullable: true })
@Column({ nullable: true })
importDate: Date;

@Field(type => String, { nullable: true })
@Column({ nullable: true })
donationType?: string;
Expand Down
18 changes: 13 additions & 5 deletions src/repositories/donationRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,12 +387,20 @@ export const getPendingDonationsIds = (): Promise<{ id: number }[]> => {
hours: Number(process.env.DONATION_VERIFICAITON_EXPIRATION_HOURS),
})
.toDate();

return Donation.find({
where: {
status: DONATION_STATUS.PENDING,
isFiat: false,
createdAt: MoreThan(date),
},
where: [
{
status: DONATION_STATUS.PENDING,
isFiat: false,
createdAt: MoreThan(date),
},
{
status: DONATION_STATUS.PENDING,
isFiat: false,
importDate: MoreThan(date),
},
aminlatifi marked this conversation as resolved.
Show resolved Hide resolved
],
select: ['id'],
});
};
Expand Down
2 changes: 1 addition & 1 deletion src/services/cronJobs/backupDonationImport.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function createBackupDonationTestCases() {
assert.equal(donation.status, DONATION_STATUS.PENDING);

// should use input createdAt not now time
assert.equal(donation.createdAt.getTime(), 1705577862000);
assert.equal(donation.importDate.getTime(), 1705577862000);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, don't change this as well.

});

it('should fail if projectId is invalid', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/services/cronJobs/backupDonationImportJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const createBackupDonation = async (
safeTransactionId,
);
const donation = (await findDonationById(Number(donationId))) as Donation;
donation!.createdAt = getCreatedAtFromMongoObjectId(donationData._id);
donation!.importDate = getCreatedAtFromMongoObjectId(donationData._id);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep it as it is, just add a line after and set the importDate to now.


return donation.save();
};
Loading