- Added the option to select an expiry date when an owner or dev creates a code
- Made it so the student's expiry date is the same as the admin when created by one
This commit is contained in:
@@ -19,7 +19,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
return;
|
||||
}
|
||||
|
||||
const {type, codes, emails} = req.body as {type: Type; codes: string[]; emails?: string[]};
|
||||
const {type, codes, emails, expiryDate} = req.body as {type: Type; codes: string[]; emails?: string[]; expiryDate: null | Date};
|
||||
const permission = PERMISSIONS.generateCode[type];
|
||||
|
||||
if (!permission.includes(req.session.user.type)) {
|
||||
@@ -29,7 +29,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
|
||||
const codePromises = codes.map(async (code, index) => {
|
||||
const codeRef = doc(db, "codes", code);
|
||||
await setDoc(codeRef, {type, code, creator: req.session.user!.id});
|
||||
await setDoc(codeRef, {type, code, creator: req.session.user!.id, expiryDate});
|
||||
|
||||
if (emails && emails.length > index) {
|
||||
const transport = prepareMailer();
|
||||
|
||||
@@ -37,7 +37,7 @@ async function login(req: NextApiRequest, res: NextApiResponse) {
|
||||
return;
|
||||
}
|
||||
|
||||
const codeData = codeDocs[0].data() as {code: string; type: Type; creator: string};
|
||||
const codeData = codeDocs[0].data() as {code: string; type: Type; creator: string; expiryDate: Date | null};
|
||||
|
||||
createUserWithEmailAndPassword(auth, email, password)
|
||||
.then(async (userCredentials) => {
|
||||
@@ -52,6 +52,7 @@ async function login(req: NextApiRequest, res: NextApiResponse) {
|
||||
isFirstLogin: codeData.type === "student",
|
||||
focus: "academic",
|
||||
type: codeData.type,
|
||||
subscriptionExpirationDate: codeData.expiryDate,
|
||||
};
|
||||
|
||||
await setDoc(doc(db, "users", userId), user);
|
||||
|
||||
Reference in New Issue
Block a user