mirror of
https://github.com/mudabbir-ahmad/MAD-Treasure-Hunt.git
synced 2026-10-08 03:00:20 +00:00
Add create game and manage game pages, update navigation and session handling for individual and business users
This commit is contained in:
1 parent
1bd640f8d5
commit
6e5fe2b8b8
21 files changed
+831
-137
No files matched your search
@@ -96,6 +96,12 @@ class DbController {
|
||||
return this.db.groups.find((group) => group.Gid === Number(gid)) || null;
|
||||
}
|
||||
|
||||
getCreatedPrivateGameByUser(uid) {
|
||||
return this.db.groups.find(
|
||||
(group) => group.CreatedByUid === Number(uid) && group.GameType === 'private',
|
||||
) || null;
|
||||
}
|
||||
|
||||
register({ username, email, password, confirmPassword, accountType }) {
|
||||
if (!username || !email || !password || !confirmPassword) {
|
||||
throw new Error('Missing required registration fields');
|
||||
@@ -213,7 +219,13 @@ class DbController {
|
||||
throw new Error('User not found');
|
||||
}
|
||||
|
||||
const existing = this.getCreatedPrivateGameByUser(user.Uid);
|
||||
if (existing) {
|
||||
return existing;
|
||||
}
|
||||
|
||||
const gid = this.nextId('group');
|
||||
const isBusinessGroup = Boolean(isBusiness);
|
||||
const group = new GroupModel({
|
||||
Gid: gid,
|
||||
GroupName: groupName,
|
||||
@@ -221,9 +233,10 @@ class DbController {
|
||||
GameType: gameType,
|
||||
AdminJoinCode: this.generateUniqueJoinCode(this.db.groups, 'AdminJoinCode'),
|
||||
CreatedByUid: user.Uid,
|
||||
MaxMemberSubgroups: isBusiness ? 999 : 1,
|
||||
MaxMemberSubgroups: isBusinessGroup ? 999 : 1,
|
||||
TeamsEnabled: true,
|
||||
ApprovedAdmins: [user.Uid],
|
||||
IsBusinessGroup: isBusinessGroup,
|
||||
ApprovedAdmins: isBusinessGroup ? [user.Uid] : [],
|
||||
CreatedAt: this.toMinuteIso(),
|
||||
});
|
||||
|
||||
@@ -236,15 +249,21 @@ class DbController {
|
||||
Gid: group.Gid,
|
||||
JoinCode: null,
|
||||
IsAdminGroup: true,
|
||||
IsGameStarted: false,
|
||||
CacheTriggerMeters: 20,
|
||||
});
|
||||
|
||||
this.createSubgroup({ gid: group.Gid, subgroupName: 'Members', cacheTriggerMeters: 20 });
|
||||
if (!isBusinessGroup) {
|
||||
this.createSubgroup({ gid: group.Gid, subgroupName: 'Members', cacheTriggerMeters: 20 });
|
||||
}
|
||||
|
||||
this.ensureMembership(user.Uid, group.Gid, 0, true);
|
||||
const ownerSgid = isBusinessGroup ? 0 : 1;
|
||||
const ownerIsAcceptedAdmin = isBusinessGroup;
|
||||
|
||||
this.ensureMembership(user.Uid, group.Gid, ownerSgid, ownerIsAcceptedAdmin);
|
||||
user.Gid = group.Gid;
|
||||
user.SGid = 0;
|
||||
user.IsAcceptedAdmin = true;
|
||||
user.SGid = ownerSgid;
|
||||
user.IsAcceptedAdmin = ownerIsAcceptedAdmin;
|
||||
|
||||
return group.toJSON();
|
||||
}
|
||||
@@ -356,6 +375,7 @@ class DbController {
|
||||
Gid: group.Gid,
|
||||
JoinCode: this.generateUniqueJoinCode(this.db.subgroups.filter((entry) => !entry.IsAdminGroup), 'JoinCode'),
|
||||
IsAdminGroup: false,
|
||||
IsGameStarted: false,
|
||||
CacheTriggerMeters: cacheTriggerMeters,
|
||||
};
|
||||
|
||||
@@ -367,6 +387,10 @@ class DbController {
|
||||
return this.db.subgroups.filter((subgroup) => subgroup.Gid === Number(gid));
|
||||
}
|
||||
|
||||
getVisibleSubgroups(gid) {
|
||||
return this.getSubgroups(gid).filter((subgroup) => Number(subgroup.SGid) > 0);
|
||||
}
|
||||
|
||||
updateSubgroupCacheSettings({ gid, sgid, triggerMeters }) {
|
||||
const subgroup = this.db.subgroups.find(
|
||||
(entry) => entry.Gid === Number(gid) && entry.SGid === Number(sgid),
|
||||
|
||||
@@ -8,6 +8,7 @@ class GroupModel {
|
||||
this.CreatedByUid = payload.CreatedByUid;
|
||||
this.MaxMemberSubgroups = payload.MaxMemberSubgroups;
|
||||
this.TeamsEnabled = Boolean(payload.TeamsEnabled);
|
||||
this.IsBusinessGroup = payload.IsBusinessGroup !== undefined ? Boolean(payload.IsBusinessGroup) : true;
|
||||
this.ApprovedAdmins = payload.ApprovedAdmins || [];
|
||||
this.CreatedAt = payload.CreatedAt;
|
||||
}
|
||||
@@ -22,6 +23,7 @@ class GroupModel {
|
||||
CreatedByUid: this.CreatedByUid,
|
||||
MaxMemberSubgroups: this.MaxMemberSubgroups,
|
||||
TeamsEnabled: this.TeamsEnabled,
|
||||
IsBusinessGroup: this.IsBusinessGroup,
|
||||
ApprovedAdmins: this.ApprovedAdmins,
|
||||
CreatedAt: this.CreatedAt,
|
||||
};
|
||||
|
||||
@@ -3,6 +3,8 @@ const session = {
|
||||
currentGid: null,
|
||||
currentSGid: null,
|
||||
currentTGid: null,
|
||||
currentIsBusiness: null,
|
||||
currentIsAcceptedAdmin: false,
|
||||
};
|
||||
|
||||
const setSessionUser = (user) => {
|
||||
@@ -10,6 +12,8 @@ const setSessionUser = (user) => {
|
||||
session.currentGid = user?.Gid ?? null;
|
||||
session.currentSGid = user?.SGid ?? null;
|
||||
session.currentTGid = user?.TGid ?? null;
|
||||
session.currentIsBusiness = user?.isBusiness ?? null;
|
||||
session.currentIsAcceptedAdmin = Boolean(user?.IsAcceptedAdmin);
|
||||
};
|
||||
|
||||
const setSessionGroup = (gid, sgid = null) => {
|
||||
@@ -19,12 +23,23 @@ const setSessionGroup = (gid, sgid = null) => {
|
||||
}
|
||||
};
|
||||
|
||||
const setSessionMembership = ({ gid = null, sgid = null, isAcceptedAdmin = false } = {}) => {
|
||||
session.currentGid = gid;
|
||||
session.currentSGid = sgid;
|
||||
session.currentIsAcceptedAdmin = Boolean(isAcceptedAdmin);
|
||||
};
|
||||
|
||||
const setSessionTeam = (tgid) => {
|
||||
session.currentTGid = tgid ?? null;
|
||||
};
|
||||
|
||||
const getSession = () => ({ ...session });
|
||||
|
||||
export { setSessionUser, setSessionGroup, setSessionTeam, getSession };
|
||||
export { setSessionUser, setSessionGroup, setSessionMembership, setSessionTeam, getSession };
|
||||
|
||||
// Default placeholder export to avoid Expo Router treating this non-component file as a route without a default.
|
||||
export default function SessionStorePlaceholder() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user