@@ -13,7 +13,7 @@ import {
1313 surveySchema
1414} from './schema' ;
1515import { requireState } from '../admin/admin' ;
16- import { meta } from '../admin/schema' ;
16+ // import { meta } from '../admin/schema';
1717
1818const proposalSchema = z . object ( {
1919 shortcode : z . string ( )
@@ -44,15 +44,16 @@ export const family = factory
4444 return ctx . text ( 'You have already completed the survey.' , 400 ) ;
4545 }
4646
47+ // Todo: consider changing states to simply survey open / closed
4748 // Ensure that parents can only complete the route during parents_open,
4849 // and students can only complete the route during students_open.
49- const metaInDb = await db . select ( ) . from ( meta ) ;
50- if ( ! metaInDb [ 0 ] ! . state . includes ( studentInDb [ 0 ] ! . role ) ) {
51- return ctx . text (
52- `It is not yet your time o ${ studentInDb [ 0 ] ! . role } .` ,
53- 400
54- ) ;
55- }
50+ // const metaInDb = await db.select().from(meta);
51+ // if (!metaInDb[0]!.state.includes(studentInDb[0]!.role)) {
52+ // return ctx.text(
53+ // `It is not yet your time o ${studentInDb[0]!.role}.`,
54+ // 400
55+ // );
56+ // }
5657
5758 const { name, interests, aboutMe, socials, gender, jmc } =
5859 ctx . req . valid ( 'json' ) ;
@@ -75,7 +76,7 @@ export const family = factory
7576 )
7677 . post (
7778 '/propose' ,
78- requireState ( 'parents_open' ) ,
79+ requireState ( 'parents_open' , 'freshers_open' ) ,
7980 grantAccessTo ( 'parent' ) ,
8081 zValidator ( 'json' , proposalSchema , async ( zRes , ctx ) => {
8182 if ( ! zRes . success ) {
@@ -159,7 +160,7 @@ export const family = factory
159160 )
160161 . delete (
161162 '/proposal' ,
162- requireState ( 'parents_open' ) ,
163+ requireState ( 'parents_open' , 'freshers_open' ) ,
163164 grantAccessTo ( 'parent' ) ,
164165 zValidator ( 'json' , proposalSchema , async ( zRes , ctx ) => {
165166 if ( ! zRes . success ) {
@@ -193,7 +194,7 @@ export const family = factory
193194 )
194195 . post (
195196 '/acceptProposal' ,
196- requireState ( 'parents_open' ) ,
197+ requireState ( 'parents_open' , 'freshers_open' ) ,
197198 grantAccessTo ( 'parent' ) ,
198199 zValidator ( 'json' , proposalSchema , async ( zRes , ctx ) => {
199200 if ( ! zRes . success ) {
@@ -204,6 +205,17 @@ export const family = factory
204205 const proposee = ctx . get ( 'shortcode' ) ! ;
205206 const { shortcode : proposer } = ctx . req . valid ( 'json' ) ;
206207
208+ const studentInDb = await db
209+ . select ( )
210+ . from ( students )
211+ . where ( eq ( students . shortcode , proposee ) ) ;
212+ if ( ! studentInDb [ 0 ] ! . completedSurvey ) {
213+ return ctx . text (
214+ 'My good fellow, how do you want to get married without having told us *anything* about yourself?' ,
215+ 400
216+ ) ;
217+ }
218+
207219 const proposalsInDb = await db
208220 . select ( )
209221 . from ( proposals )
@@ -249,7 +261,7 @@ export const family = factory
249261 )
250262 . get (
251263 '/proposals' ,
252- requireState ( 'parents_open' ) ,
264+ requireState ( 'parents_open' , 'freshers_open' ) ,
253265 grantAccessTo ( 'parent' ) ,
254266 async ctx => {
255267 const shortcode = ctx . get ( 'shortcode' ) ! ;
0 commit comments