Refactor database interaction to use centralized API; update game type retrieval and cache management logic (minor changes lol)

This commit is contained in:
bobbert committed 2026-04-03 01:19:18 +01:00
1 parent 17ed120ce8
commit d67522a71d
8 files changed
+104 -641

No files matched your search

+19 -21
View File
@@ -1,24 +1,22 @@
import usersSeed from '../../DB/users.json';
import groupsSeed from '../../DB/groups.json';
import subgroupsSeed from '../../DB/subgroups.json';
import subgroupMembershipsSeed from '../../DB/subgroup-memberships.json';
import adminWaitlistSeed from '../../DB/admin-waitlist.json';
import teamsSeed from '../../DB/teams.json';
import teamMembersSeed from '../../DB/team-members.json';
import gameDataSeed from '../../DB/game-data.json';
import gameTypesSeed from '../../DB/game-types.json';
import Constants from 'expo-constants';
const buildDbLink = () => ({
users: usersSeed,
groups: groupsSeed,
subgroups: subgroupsSeed,
subgroup_memberships: subgroupMembershipsSeed,
admin_waitlist: adminWaitlistSeed,
teams: teamsSeed,
team_members: teamMembersSeed,
game_data: gameDataSeed,
game_types: gameTypesSeed,
});
const hostFromExpo = Constants.expoConfig?.hostUri?.split(':')[0] || null;
const apiBaseUrl = 'http://localhost:3000'; // Shirish, i need to deploy the database first so... wait until that... sorry buddy...
// if you want you can run your own db locally i can send you the files for it just ask :(((
export default buildDbLink;
const postJson = async (path, payload) => {
const response = await fetch(`${apiBaseUrl}${path}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(payload),
});
const result = await response.json();
if (!response.ok) {
throw new Error(result.message || 'Request failed');
}
return result;
};
export const postDb = async (action, payload = {}) => {
return postJson('/db', { action, payload });
};