@@ -3,20 +3,24 @@ const router = express.Router();
33const firebase = require ( "firebase-admin" ) ;
44const {
55 firstSeenKey,
6- userNeedsGuardianTouchKey ,
6+ dueByKey ,
77 guardianPrivacyAuthTokenKey,
8+ userNeedsGuardianTouchKey,
89 acceptedKey,
910 acceptedByKey,
11+ variantModeKey,
1012 isUnderThirteen,
1113 getPrivacyState,
12- generateGuardianPrivacyAuthToken
14+ generateGuardianPrivacyAuthToken,
1315} = require ( "./utils" ) ;
1416
1517// /api/privacy/student/ultra-secret/view
1618// /api/privacy/student/ultra-secret/reset/under13/new
1719// /api/privacy/student/ultra-secret/reset/under13/8daysago
1820// /api/privacy/student/ultra-secret/reset/over13/new
1921// /api/privacy/student/ultra-secret/reset/over13/8daysago
22+ // /api/privacy/student/ultra-secret/reset/year8webinar/new
23+ // /api/privacy/student/ultra-secret/reset/year8webinar/31daysago
2024
2125const userDB = firebase . firestore ( ) . collection ( "users" ) ;
2226
@@ -30,10 +34,12 @@ const studentMiddleware = (req, res, next) => {
3034const getViewData = ( req ) => {
3135 const allKeys = [
3236 firstSeenKey ,
37+ dueByKey ,
3338 userNeedsGuardianTouchKey ,
3439 guardianPrivacyAuthTokenKey ,
3540 acceptedKey ,
3641 acceptedByKey ,
42+ variantModeKey ,
3743 "birthMonth" ,
3844 "birthYear" ,
3945 ] ;
@@ -51,102 +57,130 @@ const getViewData = (req) => {
5157} ;
5258
5359const getResponseBody = ( req , updateBody ) => {
54- return {
55- data : {
56- ...getViewData ( req ) ,
60+ return {
61+ data : {
62+ ...getViewData ( req ) ,
63+ ...updateBody ,
64+ privacyState : getPrivacyState ( req . user . email , {
65+ ...req . user ,
5766 ...updateBody ,
58- privacyState : getPrivacyState ( req . user . email , { ...req . user , ...updateBody } ) ,
59- isUnderThirteen : isUnderThirteen ( { ...req . user , ...updateBody } ) ,
60- } ,
61- }
62- }
63-
64- router . get (
65- "/reset/under13/new" ,
66- studentMiddleware ,
67- async ( req , res ) => {
68- const updateBody = {
69- [ firstSeenKey ] : null ,
70- [ userNeedsGuardianTouchKey ] : null ,
71- [ guardianPrivacyAuthTokenKey ] : null ,
72- [ acceptedKey ] : null ,
73- [ acceptedByKey ] : null ,
74- birthMonth : '1' ,
75- birthYear : '2025' ,
76- } ;
77-
78- await userDB . doc ( req . user . uid ) . update ( updateBody ) ;
79-
80- return res . status ( 200 ) . send ( getResponseBody ( req , updateBody ) ) ;
81- } ,
82- ) ;
83-
84- router . get (
85- "/reset/over13/new" ,
86- studentMiddleware ,
87- async ( req , res ) => {
88- const updateBody = {
89- [ firstSeenKey ] : null ,
90- [ userNeedsGuardianTouchKey ] : null ,
91- [ guardianPrivacyAuthTokenKey ] : null ,
92- [ acceptedKey ] : null ,
93- [ acceptedByKey ] : null ,
94- birthMonth : '1' ,
95- birthYear : '1990' ,
96- } ;
97-
98- await userDB . doc ( req . user . uid ) . update ( updateBody ) ;
99-
100- return res . status ( 200 ) . send ( getResponseBody ( req , updateBody ) ) ;
101- } ,
102- ) ;
103-
104- router . get (
105- "/reset/under13/8daysago" ,
106- studentMiddleware ,
107- async ( req , res ) => {
108- const updateBody = {
109- [ firstSeenKey ] : Date . now ( ) - ( 8 * 24 * 60 * 60 * 1000 ) ,
110- [ userNeedsGuardianTouchKey ] : Date . now ( ) - ( 8 * 24 * 60 * 60 * 1000 ) ,
111- [ guardianPrivacyAuthTokenKey ] : generateGuardianPrivacyAuthToken ( ) ,
112- [ acceptedKey ] : null ,
113- [ acceptedByKey ] : null ,
114- birthMonth : '1' ,
115- birthYear : '2025' ,
116- } ;
117-
118- await userDB . doc ( req . user . uid ) . update ( updateBody ) ;
119-
120- return res . status ( 200 ) . send ( getResponseBody ( req , updateBody ) ) ;
121- } ,
122- ) ;
123-
124- router . get (
125- "/reset/over13/8daysago" ,
126- studentMiddleware ,
127- async ( req , res ) => {
128- const updateBody = {
129- [ firstSeenKey ] : Date . now ( ) - ( 8 * 24 * 60 * 60 * 1000 ) ,
130- [ userNeedsGuardianTouchKey ] : null ,
131- [ guardianPrivacyAuthTokenKey ] : null ,
132- [ acceptedKey ] : null ,
133- [ acceptedByKey ] : null ,
134- birthMonth : '1' ,
135- birthYear : '1990' ,
136- } ;
137-
138- await userDB . doc ( req . user . uid ) . update ( updateBody ) ;
139-
140- return res . status ( 200 ) . send ( getResponseBody ( req , updateBody ) ) ;
141- } ,
142- ) ;
143-
144- router . get (
145- "/view" ,
146- studentMiddleware ,
147- async ( req , res ) => {
148- return res . status ( 200 ) . send ( { data : getViewData ( req ) } ) ;
149- } ,
150- ) ;
67+ } ) ,
68+ isUnderThirteen : isUnderThirteen ( { ...req . user , ...updateBody } ) ,
69+ } ,
70+ } ;
71+ } ;
72+
73+ router . get ( "/reset/under13/new" , studentMiddleware , async ( req , res ) => {
74+ const updateBody = {
75+ [ firstSeenKey ] : null ,
76+ [ dueByKey ] : null ,
77+ [ guardianPrivacyAuthTokenKey ] : null ,
78+ [ userNeedsGuardianTouchKey ] : null ,
79+ [ acceptedKey ] : null ,
80+ [ acceptedByKey ] : null ,
81+ [ variantModeKey ] : null ,
82+ birthMonth : "1" ,
83+ birthYear : "2025" ,
84+ } ;
85+
86+ await userDB . doc ( req . user . uid ) . update ( updateBody ) ;
87+
88+ return res . status ( 200 ) . send ( getResponseBody ( req , updateBody ) ) ;
89+ } ) ;
90+
91+ router . get ( "/reset/over13/new" , studentMiddleware , async ( req , res ) => {
92+ const updateBody = {
93+ [ firstSeenKey ] : null ,
94+ [ dueByKey ] : null ,
95+ [ guardianPrivacyAuthTokenKey ] : null ,
96+ [ userNeedsGuardianTouchKey ] : null ,
97+ [ acceptedKey ] : null ,
98+ [ acceptedByKey ] : null ,
99+ [ variantModeKey ] : null ,
100+ birthMonth : "1" ,
101+ birthYear : "1990" ,
102+ } ;
103+
104+ await userDB . doc ( req . user . uid ) . update ( updateBody ) ;
105+
106+ return res . status ( 200 ) . send ( getResponseBody ( req , updateBody ) ) ;
107+ } ) ;
108+
109+
110+ router . get ( "/reset/year8webinar/new" , studentMiddleware , async ( req , res ) => {
111+ const updateBody = {
112+ [ firstSeenKey ] : null ,
113+ [ dueByKey ] : Date . now ( ) + 30 * 24 * 60 * 60 * 1000 , // 30 days from now
114+ [ guardianPrivacyAuthTokenKey ] : null ,
115+ [ userNeedsGuardianTouchKey ] : null ,
116+ [ acceptedKey ] : null ,
117+ [ acceptedByKey ] : null ,
118+ [ variantModeKey ] : 'year8webinar' ,
119+ birthMonth : "1" ,
120+ birthYear : "1990" ,
121+ } ;
122+
123+ await userDB . doc ( req . user . uid ) . update ( updateBody ) ;
124+
125+ return res . status ( 200 ) . send ( getResponseBody ( req , updateBody ) ) ;
126+ } ) ;
127+
128+ router . get ( "/reset/year8webinar/31daysago" , studentMiddleware , async ( req , res ) => {
129+ const updateBody = {
130+ [ firstSeenKey ] : Date . now ( ) - 31 * 24 * 60 * 60 * 1000 , // first seen was 31 days ago
131+ [ dueByKey ] : Date . now ( ) - 24 * 60 * 60 * 1000 , // due date was 1 day ago
132+ [ userNeedsGuardianTouchKey ] : null ,
133+ [ guardianPrivacyAuthTokenKey ] : null ,
134+ [ acceptedKey ] : null ,
135+ [ acceptedByKey ] : null ,
136+ [ variantModeKey ] : 'year8webinar' ,
137+ birthMonth : "1" ,
138+ birthYear : "2025" , // Age doesn't matter for this variant
139+ } ;
140+
141+ await userDB . doc ( req . user . uid ) . update ( updateBody ) ;
142+
143+ return res . status ( 200 ) . send ( getResponseBody ( req , updateBody ) ) ;
144+ } ) ;
145+
146+ router . get ( "/reset/under13/8daysago" , studentMiddleware , async ( req , res ) => {
147+ const updateBody = {
148+ [ firstSeenKey ] : Date . now ( ) - 8 * 24 * 60 * 60 * 1000 , // first seen was 8 days ago
149+ [ dueByKey ] : Date . now ( ) - 24 * 60 * 60 * 1000 , // due date was 1 day ago
150+ [ userNeedsGuardianTouchKey ] : Date . now ( ) - 8 * 24 * 60 * 60 * 1000 , // guardian touch was 8 days ago
151+ [ guardianPrivacyAuthTokenKey ] : generateGuardianPrivacyAuthToken ( ) ,
152+ [ acceptedKey ] : null ,
153+ [ acceptedByKey ] : null ,
154+ [ variantModeKey ] : null ,
155+ birthMonth : "1" ,
156+ birthYear : "2025" ,
157+ } ;
158+
159+ await userDB . doc ( req . user . uid ) . update ( updateBody ) ;
160+
161+ return res . status ( 200 ) . send ( getResponseBody ( req , updateBody ) ) ;
162+ } ) ;
163+
164+ router . get ( "/reset/over13/8daysago" , studentMiddleware , async ( req , res ) => {
165+ const updateBody = {
166+ [ firstSeenKey ] : Date . now ( ) - 8 * 24 * 60 * 60 * 1000 , // first seen was 8 days ago
167+ [ dueByKey ] : Date . now ( ) - 24 * 60 * 60 * 1000 , // due date was 1 day ago
168+ [ userNeedsGuardianTouchKey ] : null ,
169+ [ guardianPrivacyAuthTokenKey ] : null ,
170+ [ acceptedKey ] : null ,
171+ [ acceptedByKey ] : null ,
172+ [ variantModeKey ] : null ,
173+ birthMonth : "1" ,
174+ birthYear : "1990" ,
175+ } ;
176+
177+ await userDB . doc ( req . user . uid ) . update ( updateBody ) ;
178+
179+ return res . status ( 200 ) . send ( getResponseBody ( req , updateBody ) ) ;
180+ } ) ;
181+
182+ router . get ( "/view" , studentMiddleware , async ( req , res ) => {
183+ return res . status ( 200 ) . send ( { data : getViewData ( req ) } ) ;
184+ } ) ;
151185
152186module . exports = router ;
0 commit comments