Last active
March 31, 2021 15:52
-
-
Save HonbraDev/692a24e7a4251ce3ec3b6a2aa1791537 to your computer and use it in GitHub Desktop.
Underwater
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import db from "../libs/database"; | |
import { DBUserProfile } from "./types"; | |
const getUser = (id: string): Promise<DBUserProfile> => | |
new Promise((res, rej) => | |
db | |
.ref("users") | |
.orderByChild("id") | |
.equalTo(id) | |
.once("value", (snap) => { | |
const value = snap.val(); | |
if (value) { | |
res(value[Object.keys(value)[0]]); | |
} else rej(); | |
}) | |
); | |
export default getUser; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export type PopularRooms = { | |
rooms: { | |
voiceServerId: string; | |
peoplePreviewList: { | |
numFollowers: number; | |
id: string; | |
displayName: string; | |
}[]; | |
numPeopleInside: number; | |
name: string; | |
isPrivate: boolean; | |
inserted_at: string; | |
id: string; | |
description: string; | |
creatorId: string; | |
}[]; | |
nextCursor: null; | |
initial: boolean; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { User } from "../typings/Database"; | |
import * as admin from "firebase-admin"; | |
const serviceAccount = require("../../firebaseadmin.json"); | |
admin.initializeApp({ | |
credential: admin.credential.cert(serviceAccount), | |
databaseURL: | |
"https://dodgycoin-default-rtdb.europe-west1.firebasedatabase.app", | |
}); | |
const db = admin.database(); | |
const getUser = (id: string) => | |
new Promise<User>((resolve) => | |
db.ref(`users/${id}`).once("value", (snap) => { | |
if (snap.exists()) { | |
resolve(snap.val() as User); | |
} else { | |
resolve({ monies: 0 }); | |
} | |
}) | |
); | |
const setMonies = (id: string, monies: number) => | |
new Promise((resolve, reject) => | |
db.ref(`users/${id}/monies`).set(monies).then(resolve) | |
); | |
export { getUser, setMonies }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment