62 lines
No EOL
1.5 KiB
JavaScript
62 lines
No EOL
1.5 KiB
JavaScript
export const postgresServices = {
|
|
getCallsParams: async (args) => {
|
|
let response;
|
|
try {
|
|
const { numCalls, departments, status } = args;
|
|
response = await fetch(`${process.env.EXPO_PUBLIC_DATABASE_URL}/getCallsParams`, {
|
|
method: "POST",
|
|
headers: {
|
|
apiKey: process.env.EXPO_PUBLIC_DATABASE_API_KEY,
|
|
"Content-Type": 'application/json'
|
|
},
|
|
body: JSON.stringify({
|
|
numCalls,
|
|
departments,
|
|
status
|
|
}),
|
|
});
|
|
if (!response.ok) {
|
|
throw new Error(`HTTP error! status: ${response.status}`);
|
|
}
|
|
} catch (e) {
|
|
console.error("Failed to fetch initial calls: ", e);
|
|
}
|
|
return response?.json() || [];
|
|
},
|
|
createUser: async (args) => {
|
|
try {
|
|
const {
|
|
firstName,
|
|
lastName,
|
|
number,
|
|
email,
|
|
provider,
|
|
departments,
|
|
token,
|
|
uid
|
|
} = args;
|
|
await fetch(`${process.env.EXPO_PUBLIC_DATABASE_URL}/createUser`, {
|
|
method: "POST",
|
|
headers: {
|
|
apiKey: process.env.EXPO_PUBLIC_DATABASE_API_KEY,
|
|
"Content-Type": 'application/json'
|
|
},
|
|
body: JSON.stringify({
|
|
firstName,
|
|
lastName,
|
|
number,
|
|
email,
|
|
provider,
|
|
departments,
|
|
globalRole: 'user',
|
|
primaryDept,
|
|
token,
|
|
firebaseUid: uid
|
|
}),
|
|
});
|
|
} catch (e) {
|
|
console.error("Failed to Add User to Database: ", e);
|
|
}
|
|
return 'User Added to Database';
|
|
}
|
|
} |