Skip to content
Merged
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
22 changes: 19 additions & 3 deletions server/src/cron/subscription-expiry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,37 @@ let cronJob: cron.ScheduledTask | null = null;
async function expireSubscriptions(): Promise<void> {
const now = new Date();

const result = await prisma.user.updateMany({
// Find users whose subscriptions are expiring
const expiringUsers = await prisma.user.findMany({
where: {
subscriptionStatus: "ACTIVE",
subscriptionEndDate: { lt: now },
subscriptionPlan: { in: ["MONTHLY", "YEARLY"] },
},
select: { id: true },
});

if (expiringUsers.length === 0) return;

const userIds = expiringUsers.map((u) => u.id);

// Update them in bulk
await prisma.user.updateMany({
where: { id: { in: userIds } },
data: {
subscriptionStatus: "EXPIRED",
subscriptionPlan: "FREE",
},
});

if (result.count > 0) {
console.log(`[Cron] Expired ${result.count} subscription(s)`);
// Invalidate cache for each user
const { cacheDel } = await import("../utils/cache.js");
for (const userId of userIds) {
await cacheDel(`profile:me:${userId}`).catch(() => {});
await cacheDel(`profile:public:${userId}`).catch(() => {});
}

console.log(`[Cron] Expired ${userIds.length} subscription(s) and cleared profile cache.`);
}

export function startSubscriptionExpiryCron(): void {
Expand Down
21 changes: 12 additions & 9 deletions server/src/module/ats/__tests__/ats.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,12 @@ function mockCacheMiss() {

function mockValidPdf(text = VALID_RESUME_TEXT) {
vi.mocked(PDFParse).mockImplementation(
() =>
({
function () {
return {
getText: vi.fn().mockResolvedValue({ text }),
destroy: vi.fn().mockResolvedValue(undefined),
}) as any,
} as any;
}
);
}

Expand Down Expand Up @@ -183,11 +184,12 @@ describe("AtsService", () => {
mockUserOwnsResume();
mockCacheMiss();
vi.mocked(PDFParse).mockImplementation(
() =>
({
function () {
return {
getText: vi.fn().mockResolvedValue({ text: "too short" }),
destroy: vi.fn().mockResolvedValue(undefined),
}) as any,
} as any;
}
);

await expect(
Expand Down Expand Up @@ -466,11 +468,12 @@ describe("AtsService", () => {
it("throws when PDF text extraction yields insufficient content", async () => {
mockUserOwnsResume();
vi.mocked(PDFParse).mockImplementation(
() =>
({
function () {
return {
getText: vi.fn().mockResolvedValue({ text: "tiny" }),
destroy: vi.fn().mockResolvedValue(undefined),
}) as any,
} as any;
}
);

await expect(
Expand Down
Loading