Skip to content

Commit b60bb12

Browse files
authored
Merge pull request #59 from devcon-plus-member-platform
2 parents 7e91948 + 8ab8eed commit b60bb12

19 files changed

Lines changed: 989 additions & 31 deletions

‎.claude/CLAUDE.md‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,39 @@ Page gutters: px-4
802802
Safe bottom: pb-24 in scroll containers (clears floating nav)
803803
```
804804

805+
### Chips & Tab Toggles (white-outlined style — updated June 2026)
806+
807+
Pill-shaped filter chips and segmented tab toggles use a **white, outlined** treatment —
808+
NOT a filled light-blue (`bg-primary/10`) inactive state. Every chip/tab carries a 1px `border`
809+
on ALL states so widths never shift when selection changes. Two variants:
810+
811+
**Segmented tab toggle** — full-width `flex-1` buttons that switch between views (e.g. Discover /
812+
My Tickets, Updates / Featured, Ways to Earn / Share & Earn, Redeem / Missions). Active = solid fill:
813+
```
814+
base: ...rounded-full ... border (add `border` to the base class)
815+
active: bg-primary text-white font-semibold border-primary shadow-sm
816+
inactive: bg-white text-slate-700 font-medium border-slate-200
817+
```
818+
819+
**Filter chip** — horizontal-scroll pills that narrow a list (e.g. All Events / Near You / DEVCON,
820+
points-history filters, mission/reward category chips). Active = white with a colored border:
821+
```
822+
base: ...rounded-full ... border (add `border` to the base class)
823+
active: bg-white text-primary font-semibold border-primary
824+
inactive: bg-white text-slate-500 font-medium border-slate-200
825+
```
826+
827+
Notes:
828+
- On the **organizer** surface (non-themed), swap `primary` → `blue`: active tab toggle is
829+
`bg-blue text-white border-blue shadow-sm`, inactive `bg-white text-slate-700 border-slate-200`.
830+
- Both variants assume a **light backdrop** (`bg-slate-50` glassmorphism header or page body).
831+
Do not place white-outlined chips on the blue header ellipse.
832+
- This is distinct from `<ChipBar />` (a slate-100-track segmented control with a white active pill)
833+
and from the AdminCMS folder-tab bar (`rounded-t-lg` underline tabs) — leave those as-is.
834+
- Files using this pattern: `EventsList`, `Dashboard` (Updates/Featured), `Points`,
835+
`PointsHistory`, `Rewards` (main tab + mission/category chips), `organizer/RewardsManagement`.
836+
`solar-icon-set` count/badge spans inside a chip keep their own styling.
837+
805838
### Animation (framer-motion)
806839
```js
807840
// web/src/lib/animation.ts — always import from here, never redefine inline
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { IsString, MaxLength, MinLength } from 'class-validator';
2+
3+
export class RejectSubmissionDto {
4+
@IsString()
5+
@MinLength(1)
6+
@MaxLength(1000)
7+
adminRemarks!: string;
8+
}

‎server/src/missions/missions.controller.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { Roles } from '../common/authz/roles.decorator';
1616
import { RolesGuard } from '../common/authz/roles.guard';
1717
import { IdParamDto } from '../common/dto/id-param.dto';
1818
import { CreateMissionDto } from './dto/create-mission.dto';
19+
import { RejectSubmissionDto } from './dto/reject-submission.dto';
1920
import { SubmitMissionDto } from './dto/submit-mission.dto';
2021
import { UpdateMissionDto } from './dto/update-mission.dto';
2122
import { MissionsService } from './missions.service';
@@ -43,6 +44,14 @@ export class MissionsController {
4344
return this.service.getPendingQueue();
4445
}
4546

47+
/** GET /api/missions/submissions — hq_admin: all submissions across all statuses */
48+
@Get('submissions')
49+
@UseGuards(RolesGuard)
50+
@Roles('hq_admin')
51+
getAllSubmissions() {
52+
return this.service.getAllSubmissionsAdmin();
53+
}
54+
4655
/** POST /api/missions/submissions/:id/approve — hq_admin: approve_mission_winner RPC */
4756
@Post('submissions/:id/approve')
4857
@HttpCode(HttpStatus.OK)
@@ -52,6 +61,15 @@ export class MissionsController {
5261
return this.service.approveMissionWinner(id);
5362
}
5463

64+
/** POST /api/missions/submissions/:id/reject — hq_admin: reject with admin remarks */
65+
@Post('submissions/:id/reject')
66+
@HttpCode(HttpStatus.OK)
67+
@UseGuards(RolesGuard)
68+
@Roles('hq_admin')
69+
rejectSubmission(@Param() { id }: IdParamDto, @Body() { adminRemarks }: RejectSubmissionDto) {
70+
return this.service.rejectSubmission(id, adminRemarks);
71+
}
72+
5573
// ── Member: consolidated data ─────────────────────────────────────────────
5674

5775
/** GET /api/missions — active missions + caller's participants + submissions */

‎server/src/missions/missions.repository.ts‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,40 @@ export class MissionsRepository extends BaseRepository {
120120
);
121121
}
122122

123+
async findAllSubmissionsAdmin(): Promise<MissionSubmissionWithDetails[]> {
124+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
125+
const { data, error } = await (this.db as any)
126+
.from('mission_submissions')
127+
.select('*, missions:mission_id(title, xp_reward), profiles:user_id(full_name, email, spendable_points, lifetime_points)')
128+
.order('submitted_at', { ascending: false })
129+
.limit(500);
130+
131+
if (error) throw new BadRequestException((error as { message: string }).message);
132+
133+
return (data ?? []).map((row: Record<string, unknown>) => {
134+
const m = Array.isArray(row.missions) ? (row.missions as unknown[])[0] : row.missions;
135+
const p = Array.isArray(row.profiles) ? (row.profiles as unknown[])[0] : row.profiles;
136+
const mObj = m as { title?: string; xp_reward?: number } | null;
137+
const pObj = p as { full_name?: string; email?: string; spendable_points?: number; lifetime_points?: number } | null;
138+
return {
139+
id: (row.id ?? '') as string,
140+
mission_id: (row.mission_id ?? '') as string,
141+
user_id: (row.user_id ?? '') as string,
142+
pr_link: (row.pr_link ?? null) as string | null,
143+
status: (row.status ?? 'pending') as MissionSubmissionWithDetails['status'],
144+
submitted_at: (row.submitted_at ?? null) as string | null,
145+
admin_remarks: (row.admin_remarks ?? null) as string | null,
146+
reviewed_at: (row.reviewed_at ?? null) as string | null,
147+
mission_title: mObj?.title ?? 'Unknown Mission',
148+
xp_reward: mObj?.xp_reward ?? 0,
149+
member_name: pObj?.full_name ?? 'Unknown',
150+
member_email: pObj?.email ?? '',
151+
spendable_points: pObj?.spendable_points ?? 0,
152+
lifetime_points: pObj?.lifetime_points ?? 0,
153+
} satisfies MissionSubmissionWithDetails;
154+
});
155+
}
156+
123157
async findPendingQueue(): Promise<MissionSubmissionWithDetails[]> {
124158
// eslint-disable-next-line @typescript-eslint/no-explicit-any
125159
const { data, error } = await (this.db as any)
@@ -188,4 +222,12 @@ export class MissionsRepository extends BaseRepository {
188222
} as never);
189223
if (error) throw new BadRequestException(error.message);
190224
}
225+
226+
async rejectSubmission(subId: string, adminRemarks: string): Promise<void> {
227+
const { error } = await this.db.rpc('reject_mission_submission' as never, {
228+
p_submission_id: subId,
229+
p_admin_remarks: adminRemarks,
230+
} as never);
231+
if (error) throw new BadRequestException(error.message);
232+
}
191233
}

‎server/src/missions/missions.service.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,18 @@ export class MissionsService {
6161
);
6262
}
6363

64+
getAllSubmissionsAdmin(): Promise<MissionSubmissionWithDetails[]> {
65+
return this.repo.findAllSubmissionsAdmin();
66+
}
67+
6468
getPendingQueue(): Promise<MissionSubmissionWithDetails[]> {
6569
return this.repo.findPendingQueue();
6670
}
6771

72+
rejectSubmission(subId: string, adminRemarks: string): Promise<void> {
73+
return this.repo.rejectSubmission(subId, adminRemarks);
74+
}
75+
6876
async createMission(dto: CreateMissionDto): Promise<Mission> {
6977
const mission = await this.repo.createMission(dto);
7078
await this.cache.del(CacheKeys.MISSIONS_ADMIN_LIST);

‎server/src/points/points.controller.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ export class PointsController {
5050
return this.service.getPointSummary(user);
5151
}
5252

53+
/** GET /api/points/admin/user/:id — hq_admin: recent transactions for any member */
54+
@Get('admin/user/:id')
55+
@UseGuards(RolesGuard)
56+
@Roles('hq_admin')
57+
getAdminUserTransactions(@Param() { id }: IdParamDto) {
58+
return this.service.getAdminUserTransactions(id);
59+
}
60+
5361
// ── XP Tiers ─────────────────────────────────────────────────────────────
5462

5563
/** GET /api/points/tiers — list all XP tier definitions */

‎server/src/points/points.repository.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ export class PointsRepository extends BaseRepository {
4141
};
4242
}
4343

44+
async findTransactionsByUserId(userId: string, limit = 10): Promise<PointTransaction[]> {
45+
const result = await this.db
46+
.from('point_transactions')
47+
.select('*')
48+
.eq('user_id', userId)
49+
.order('created_at', { ascending: false })
50+
.limit(limit);
51+
return this.unwrap(
52+
result as { data: PointTransaction[] | null; error: { message: string } | null },
53+
);
54+
}
55+
4456
// ── XP Tiers (admin) ──────────────────────────────────────────────────────
4557

4658
async findAllTiers(): Promise<XpTier[]> {

‎server/src/points/points.service.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ export class PointsService {
3333
return this.repo.findPointSummary(user.profileId);
3434
}
3535

36+
getAdminUserTransactions(userId: string): Promise<PointTransaction[]> {
37+
return this.repo.findTransactionsByUserId(userId, 10);
38+
}
39+
3640
// xp_tiers is global reference data (milestone definitions) — shared key.
3741
getAllTiers(): Promise<XpTier[]> {
3842
return this.cache.getOrSet(CacheKeys.XP_TIERS, CACHE_TTL.TIERS, () =>

‎server/src/supabase/types.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ export interface MissionSubmissionWithDetails extends MissionSubmission {
7878
mission_title: string;
7979
member_name: string;
8080
member_email: string;
81+
// Extended fields returned by the admin full-submissions endpoint
82+
xp_reward?: number;
83+
spendable_points?: number;
84+
lifetime_points?: number;
85+
admin_remarks?: string | null;
86+
reviewed_at?: string | null;
8187
}
8288

8389
export interface XpTier {
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
-- ── Mission Submissions: review audit columns + reject RPC ───────────────────
2+
-- Adds the admin-review audit trail to mission_submissions and defines the
3+
-- reject_mission_submission server-side RPC.
4+
-- Idempotent — safe to re-apply against a DB that already has these changes
5+
-- (e.g. if the 20260612_points_approval.sql was applied directly on an earlier branch).
6+
7+
-- 1. Audit columns
8+
ALTER TABLE mission_submissions
9+
ADD COLUMN IF NOT EXISTS admin_remarks text,
10+
ADD COLUMN IF NOT EXISTS reviewed_by uuid REFERENCES profiles(id),
11+
ADD COLUMN IF NOT EXISTS reviewed_at timestamptz;
12+
13+
-- 2. Widen status CHECK to include 'rejected'
14+
ALTER TABLE mission_submissions DROP CONSTRAINT IF EXISTS mission_submissions_status_check;
15+
ALTER TABLE mission_submissions
16+
ADD CONSTRAINT mission_submissions_status_check
17+
CHECK (status IN ('pending', 'approved', 'rejected'));
18+
19+
-- 3. RLS: allow service_role (NestJS backend) to update submissions for review
20+
DO $$
21+
BEGIN
22+
IF NOT EXISTS (
23+
SELECT 1 FROM pg_policies
24+
WHERE tablename = 'mission_submissions' AND policyname = 'submissions_admin_review'
25+
) THEN
26+
EXECUTE $policy$
27+
CREATE POLICY "submissions_admin_review" ON mission_submissions
28+
FOR UPDATE USING (
29+
EXISTS (SELECT 1 FROM profiles WHERE id = auth.uid()
30+
AND role IN ('hq_admin', 'super_admin'))
31+
)
32+
$policy$;
33+
END IF;
34+
END $$;
35+
36+
-- 4. approve_mission_winner — stamp reviewer + reviewed_at (idempotent replace)
37+
CREATE OR REPLACE FUNCTION approve_mission_winner(sub_id uuid)
38+
RETURNS void
39+
LANGUAGE plpgsql
40+
SECURITY DEFINER
41+
AS $$
42+
DECLARE
43+
v_mission_id uuid;
44+
v_user_id uuid;
45+
v_xp_reward integer;
46+
v_title text;
47+
BEGIN
48+
SELECT ms.mission_id, ms.user_id, m.xp_reward, m.title
49+
INTO v_mission_id, v_user_id, v_xp_reward, v_title
50+
FROM mission_submissions ms
51+
JOIN missions m ON m.id = ms.mission_id
52+
WHERE ms.id = sub_id AND ms.status = 'pending';
53+
54+
IF NOT FOUND THEN
55+
RAISE EXCEPTION 'Submission not found or already processed';
56+
END IF;
57+
58+
UPDATE mission_submissions
59+
SET status = 'approved',
60+
reviewed_by = auth.uid(),
61+
reviewed_at = NOW()
62+
WHERE id = sub_id;
63+
64+
UPDATE missions SET status = 'claimed' WHERE id = v_mission_id;
65+
66+
UPDATE profiles
67+
SET spendable_points = COALESCE(spendable_points, 0) + v_xp_reward,
68+
lifetime_points = COALESCE(lifetime_points, 0) + v_xp_reward
69+
WHERE id = v_user_id;
70+
71+
INSERT INTO point_transactions (user_id, amount, description, source)
72+
VALUES (v_user_id, v_xp_reward, 'Mission completed: ' || v_title, 'bonus');
73+
END;
74+
$$;
75+
76+
-- 5. reject_mission_submission — called exclusively by NestJS service role
77+
-- auth.uid() is NULL under service role; authorization is enforced at the API layer.
78+
CREATE OR REPLACE FUNCTION reject_mission_submission(
79+
p_submission_id uuid,
80+
p_admin_remarks text
81+
) RETURNS void
82+
LANGUAGE plpgsql
83+
SECURITY DEFINER AS $$
84+
BEGIN
85+
UPDATE mission_submissions
86+
SET status = 'rejected',
87+
admin_remarks = p_admin_remarks,
88+
reviewed_at = NOW()
89+
WHERE id = p_submission_id AND status = 'pending';
90+
91+
IF NOT FOUND THEN
92+
RAISE EXCEPTION 'Submission not found or already processed';
93+
END IF;
94+
END;
95+
$$;
96+
97+
-- 6. Lock down execute to service_role only (idempotent)
98+
REVOKE EXECUTE ON FUNCTION public.reject_mission_submission(uuid, text) FROM PUBLIC, anon, authenticated;
99+
GRANT EXECUTE ON FUNCTION public.reject_mission_submission(uuid, text) TO service_role;
100+
101+
REVOKE EXECUTE ON FUNCTION public.approve_mission_winner(uuid) FROM PUBLIC, anon, authenticated;
102+
GRANT EXECUTE ON FUNCTION public.approve_mission_winner(uuid) TO service_role;

0 commit comments

Comments
 (0)