@prisma/client#Profile TypeScript Examples
The following examples show how to use
@prisma/client#Profile.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Database.ts From Mandroc with GNU General Public License v3.0 | 6 votes |
/**
* Find or creates a profile with the provided id.
*
* @param id User id.
*/
static async findProfile(id: string): Promise<Profile> {
return await Database.PRISMA.profile.upsert({
where: { id },
create: { id },
update: {}
});
}
Example #2
Source File: Economy.ts From Mandroc with GNU General Public License v3.0 | 5 votes |
doLootbox(profile: Profile, message: Message) {
void profile;
void message;
// if (Math.random() < 0.33) {
// const randomItem = this.lootBoxItems.random();
//
// switch (randomItem.type) {
// case "gems":
// profile.pocket += randomItem.value;
// message.channel
// .send(
// `${message.author}, you found a bag full of gems! Their value, of \`${randomItem.value} ₪, has been added to your pocket!\``
// )
// .then(m => m.delete({ timeout: 6000 }));
//
// break;
//
// case "item":
// profile.pocket += randomItem.value;
// message.channel
// .send(
// `Amazing, you both leveled up and found a: \`${randomItem.name}\`, you sold it and got **${randomItem.value} ₪**`
// )
// .then(m => m.delete({ timeout: 6000 }));
//
// break;
//
// case "tool":
// const tool = this.toolList.random();
// profile.inventory.push(tool);
// message.channel
// .send(
// `${message.author}, you bent down and found a really awesome \`${tool.name}\`.`
// )
// .then(m => m.delete({ timeout: 6000 }));
//
// break;
//
// case "bodyguard":
// if (profile.bodyguard) {
// message.channel
// .send(
// `${message.author}, you met a really nice guy who offered to be your bodyguard, you rejected though.`
// )
// .then(m => m.delete({ timeout: 6000 }));
// } else {
// const bodyguard = [
// "deluxe",
// "gold",
// "rookie"
// ].random() as BodyguardTier;
// profile.bodyguard = bodyguard;
// message.channel
// .send(
// `${message.author}, a bodyguard of the tier **${bodyguard}** offered to protect you, and you said *yes please!*`
// )
// .then(m => m.delete({ timeout: 6000 }));
// }
//
// break;
// }
// }
}
Example #3
Source File: profile.ts From Mandroc with GNU General Public License v3.0 | 5 votes |
/**
* React-esque hooks for user profiles.
*
* @param userId ID of the user
*/
export async function useProfile(userId: string): Promise<ProfileHook> {
const profile = await Database.findProfile(userId);
const o_o = new Proxy<Profile>(profile, {
get: (_, p: PropertyKey): any => Reflect.get(profile, p),
has: (_, p: PropertyKey): boolean => Reflect.has(profile, p),
set(_, __, ___): boolean {
throw new Error("Setting a hook value is not allowed, use the caching update method instead")
}
});
let updateCache: ProfileUpdate | null = null
async function update(data?: ProfileUpdate, push: boolean = true) {
if (push) {
if (!data && !updateCache) {
throw new Error("Can't update a profile with no data.")
}
Database.PRISMA.profile.update({
where: { id: profile!.id },
data: {
...updateCache,
...data
}
})
return
}
if (!data) {
throw new Error("Can't cache changes if no data is provided.")
}
updateCache = Object.assign(updateCache ?? {}, data);
}
return [ o_o, update ]
}
Example #4
Source File: GuildMember.ts From Mandroc with GNU General Public License v3.0 | 5 votes |
async getProfile(): Promise<Profile> {
return Database.findProfile(this.id);
}