Skip to content

Commit 8144a39

Browse files
authored
feat: allow parents & students to sign up at the same time (#24)
1 parent 3bd24a2 commit 8144a39

File tree

4 files changed

+53
-36
lines changed

4 files changed

+53
-36
lines changed

app/pages/index.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ const data = computed(() => {
1717
};
1818
case 'freshers_open':
1919
return {
20-
notificationTitle: 'Freshers signup is now open!',
21-
notificationDescription: 'Sign up to be adopted by a DoCSoc family'
20+
notificationTitle: 'Parents & freshers signups are now open!',
21+
notificationDescription:
22+
'Parents, sign up to help freshers settle into university life! Freshers, sign up to be adopted by a DoCSoc family!'
2223
};
2324
case 'closed':
2425
return {

app/pages/portal.vue

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,22 @@ definePageMeta({
6161
</CardDetails>
6262
</div>
6363
<div v-else-if="currentState == 'freshers_open'">
64-
<CardDetails v-if="currentUser!.role == 'fresher'">
65-
<strong>Fresher's survey. [OPEN]</strong>
66-
<CardText>
67-
If you have not completed our survey yet, please complete the
68-
<NuxtLink to="/survey">survey</NuxtLink>
69-
so we can assign a family to you.
64+
<CardDetails>
65+
<strong>Mums and Dads Survey. [OPEN]</strong>
66+
<CardText v-if="!currentUser!.completedSurvey">
67+
Please complete the
68+
<NuxtLink to="/survey">Mums and Dads survey</NuxtLink>
69+
so we can assign you to a happy family!
7070
</CardText>
71-
</CardDetails>
72-
<CardDetails v-else>
73-
<strong>Parent's survey & proposals. [CLOSED]</strong>
74-
<CardText>
75-
Visit your
76-
<NuxtLink to="/family">family page</NuxtLink>
77-
to see your family details.
71+
<CardText v-else-if="currentUser!.role == 'fresher'">
72+
Thank you for completing the survey! Be on the look out for an email
73+
with more details once families have been assigned.
74+
</CardText>
75+
<CardText v-else-if="currentUser!.role == 'parent'">
76+
Thank you for completing the survey! If you haven't yet, please
77+
send/accept a
78+
<NuxtLink to="/proposals">proposal</NuxtLink>
79+
to mark the start of your happy family.
7880
</CardText>
7981
</CardDetails>
8082
</div>

hono/family/family.ts

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
surveySchema
1414
} from './schema';
1515
import { requireState } from '../admin/admin';
16-
import { meta } from '../admin/schema';
16+
// import { meta } from '../admin/schema';
1717

1818
const 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')!;

hono/seed.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,17 @@ if (push) {
110110

111111
console.log('--- Adding state to the db...');
112112
// Add the required meta values for state
113-
await db.insert(meta).values({
114-
id: 1,
115-
state: 'parents_open'
116-
});
113+
await db
114+
.insert(meta)
115+
.values({
116+
id: 1,
117+
state: 'parents_open'
118+
})
119+
.onConflictDoNothing();
117120
console.log('--- State added! ---');
118-
} else {
119-
console.log('--- Writing JSON to file... ---');
121+
}
122+
console.log('--- Writing JSON to file... ---');
120123

121-
await Bun.write('students.json', JSON.stringify(allStudents, null, 2));
124+
await Bun.write('students.json', JSON.stringify(allStudents, null, 2));
122125

123-
console.log('--- Wrote JSON to file! ---');
124-
}
126+
console.log('--- Wrote JSON to file! ---');

0 commit comments

Comments
 (0)