Skip to content

Commit dc73d76

Browse files
authored
Merge pull request #103 from hackclub/revert-94-main
Revert "same as past pr but this time for staging"
2 parents 8524f7e + 7812029 commit dc73d76

File tree

6 files changed

+37
-106
lines changed

6 files changed

+37
-106
lines changed

drizzle/0025_add_claimed_at.sql

Lines changed: 0 additions & 1 deletion
This file was deleted.

server.js

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,16 @@
11
import express from 'express';
22
import { handler } from './build/handler.js';
3-
import { CronJob } from 'cron';
3+
// import { CronJob } from 'cron';
44

5-
// Run daily at midnight UTC to unclaim expired print claims (older than 7 days)
6-
new CronJob(
7-
'0 0 * * *', // Every day at midnight
8-
async function () {
9-
try {
10-
const baseUrl = process.env.PUBLIC_BASE_URL || `http://localhost:${process.env.PORT ?? 3000}`;
11-
const response = await fetch(`${baseUrl}/api/cron/unclaim-expired`, {
12-
method: 'POST',
13-
headers: {
14-
Authorization: `Bearer ${process.env.APP_SECRET_KEY}`
15-
}
16-
});
17-
const result = await response.json();
18-
console.log(`[Cron] Unclaimed ${result.unclaimedCount} expired print claims`);
19-
} catch (error) {
20-
console.error('[Cron] Failed to unclaim expired prints:', error);
21-
}
22-
},
23-
null,
24-
true,
25-
'UTC'
26-
);
5+
// new CronJob(
6+
// '* * * * * *', // cronTime
7+
// function () {
8+
// console.log('You will see this message every second');
9+
// }, // onTick
10+
// null, // onComplete
11+
// true, // start
12+
// 'Europe/London' // timeZone
13+
// );
2714

2815
const app = express();
2916

src/lib/server/db/schema.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ export const project = pgTable('project', {
8484

8585
status: projectStatusEnum().notNull().default('building'),
8686
printedBy: integer().references(() => user.id),
87-
claimedAt: timestamp(), // When the project was claimed for printing
8887

8988
submittedToAirtable: boolean().default(false),
9089

src/routes/api/cron/unclaim-expired/+server.ts

Lines changed: 0 additions & 64 deletions
This file was deleted.

src/routes/dashboard/admin/print/[id]/+page.server.ts

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { eq, and, asc, sql } from 'drizzle-orm';
55
import type { Actions } from './$types';
66
import { sendSlackDM } from '$lib/server/slack.js';
77
import { getReviewHistory } from '../../getReviewHistory.server';
8+
import { getCurrentlyPrinting } from '../utils.server';
89

910
export async function load({ locals, params }) {
1011
if (!locals.user) {
@@ -79,10 +80,13 @@ export async function load({ locals, params }) {
7980
.where(and(eq(devlog.projectId, queriedProject.project.id), eq(devlog.deleted, false)))
8081
.orderBy(asc(devlog.createdAt));
8182

83+
const currentlyPrinting = await getCurrentlyPrinting(locals.user);
84+
8285
return {
8386
project: queriedProject,
8487
devlogs,
85-
reviews: await getReviewHistory(id)
88+
reviews: await getReviewHistory(id),
89+
currentlyPrinting
8690
};
8791
}
8892

@@ -95,8 +99,16 @@ export const actions = {
9599
throw error(403, { message: 'oi get out' });
96100
}
97101

102+
const currentlyPrinting = await getCurrentlyPrinting(locals.user);
103+
98104
const id: number = parseInt(params.id);
99105

106+
if (currentlyPrinting && currentlyPrinting.id !== id) {
107+
return error(400, {
108+
message: 'you are already printing something else right now'
109+
});
110+
}
111+
100112
const [queriedProject] = await db
101113
.select({
102114
id: project.id,
@@ -124,8 +136,7 @@ export const actions = {
124136
.update(project)
125137
.set({
126138
status: 'printing',
127-
printedBy: locals.user.id,
128-
claimedAt: new Date()
139+
printedBy: locals.user.id
129140
})
130141
.where(eq(project.id, id));
131142

@@ -170,8 +181,7 @@ export const actions = {
170181
.update(project)
171182
.set({
172183
status: 't1_approved',
173-
printedBy: null,
174-
claimedAt: null
184+
printedBy: null
175185
})
176186
.where(eq(project.id, id));
177187

@@ -186,13 +196,20 @@ export const actions = {
186196
throw error(403, { message: 'oi get out' });
187197
}
188198

199+
const currentlyPrinting = await getCurrentlyPrinting(locals.user);
200+
189201
const id: number = parseInt(params.id);
190202

203+
if (!currentlyPrinting || currentlyPrinting.id !== id) {
204+
return error(400, {
205+
message: "you can only print a project if you've marked it as you're printing it"
206+
});
207+
}
208+
191209
const [queriedProject] = await db
192210
.select({
193211
id: project.id,
194-
status: project.status,
195-
printedBy: project.printedBy
212+
status: project.status
196213
})
197214
.from(project)
198215
.where(and(eq(project.id, id), eq(project.deleted, false)))
@@ -206,12 +223,6 @@ export const actions = {
206223
return error(403, { message: 'project is not marked as currently printing' });
207224
}
208225

209-
if (queriedProject.printedBy !== locals.user.id) {
210-
return error(400, {
211-
message: "you can only print a project if you've marked it as you're printing it"
212-
});
213-
}
214-
215226
const data = await request.formData();
216227
const filamentUsed = data.get('filament');
217228
const notes = data.get('notes')?.toString();
@@ -241,8 +252,7 @@ export const actions = {
241252
await db
242253
.update(project)
243254
.set({
244-
status: 'printed',
245-
claimedAt: null
255+
status: 'printed'
246256
})
247257
.where(eq(project.id, id));
248258

src/routes/dashboard/admin/print/[id]/+page.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@
112112

113113
<h2 class="mt-2 text-2xl font-bold">Printering area</h2>
114114

115-
{#if data.project.project.status === 't1_approved' || (data.project.project.status === 'printing' && data.project.project.printedBy === data.user.id)}
115+
{#if (data.project.project.status === 't1_approved' && !data.currentlyPrinting) || (data.project.project.status === 'printing' && data.project.project.printedBy === data.user.id)}
116116
<div class="themed-box flex flex-col gap-3 p-3">
117-
{#if data.project.project.status === 't1_approved'}
117+
{#if data.project.project.status === 't1_approved' && !data.currentlyPrinting}
118118
<form
119119
method="POST"
120120
action="?/markForPrint"

0 commit comments

Comments
 (0)