11import { db } from '$lib/server/db/index.js' ;
2- import { devlog , project , clubMembership , club } from '$lib/server/db/schema.js' ;
2+ import { devlog , project , clubMembership , club , ship } from '$lib/server/db/schema.js' ;
33import { error , fail , redirect } from '@sveltejs/kit' ;
4- import { eq , and , or , sql } from 'drizzle-orm' ;
4+ import { eq , and , or , sql , desc } from 'drizzle-orm' ;
55import type { Actions } from './$types' ;
66import { sendSlackDM } from '$lib/server/slack.js' ;
77import { isValidUrl } from '$lib/utils' ;
@@ -10,7 +10,6 @@ import { extname } from 'path';
1010import { env } from '$env/dynamic/private' ;
1111import { PutObjectCommand } from '@aws-sdk/client-s3' ;
1212import { S3 } from '$lib/server/s3' ;
13- import { ship } from '$lib/server/db/schema.js' ;
1413import { sanitizeUrl } from '@braintree/sanitize-url' ;
1514import { END_DATE } from '$lib/defs' ;
1615
@@ -75,7 +74,8 @@ export async function load({ params, locals }) {
7574
7675 return {
7776 project : queriedProject ,
78- clubMembership : membership . length > 0 ? membership [ 0 ] : null
77+ clubMembership : membership . length > 0 ? membership [ 0 ] : null ,
78+ lastIsClubsShip : await lastIsClubsShip ( id )
7979 } ;
8080}
8181
@@ -282,7 +282,7 @@ export const actions = {
282282 }
283283 }
284284
285- if ( END_DATE <= new Date ( ) && queriedProject . status === 'building' && clubIdForShip === null ) {
285+ if ( END_DATE <= new Date ( ) && clubIdForShip === null && ( queriedProject . status === 'building' || await lastIsClubsShip ( id ) ) ) {
286286 return error ( 400 , { message : "can't submit individual project past end date" } ) ;
287287 }
288288
@@ -349,3 +349,18 @@ export const actions = {
349349 return redirect ( 303 , '/dashboard/projects' ) ;
350350 }
351351} satisfies Actions ;
352+
353+ async function lastIsClubsShip ( id : number ) {
354+ const [ latestShip ] = await db
355+ . select ( {
356+ clubId : ship . clubId
357+ } )
358+ . from ( ship )
359+ . where ( eq ( ship . projectId , id ) )
360+ . orderBy ( desc ( ship . timestamp ) )
361+ . limit ( 1 ) ;
362+
363+ if ( latestShip && latestShip . clubId ) return true ;
364+
365+ return false ;
366+ }
0 commit comments