@prisma/client#Tag TypeScript Examples

The following examples show how to use @prisma/client#Tag. 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: TagResolver.ts    From Mandroc with GNU General Public License v3.0 6 votes vote down vote up
export class TagResolver extends Resolver<Tag> {
  constructor() {
    super("tag", {
      name: "tag"
    });
  }

  async exec(message: Message, phrase?: string | null): Promise<Tag | Flag | null> {
    if (!message.guild || !phrase) {
      return Flag.fail(phrase);
    }

    return await Database.findTag(phrase);
  }
}
Example #2
Source File: Database.ts    From Mandroc with GNU General Public License v3.0 6 votes vote down vote up
/**
   * Finds a tool in a user's inventory.
   *
   * @param query Name or alias of the tag,
   */
  static async findTag(query: string): Promise<Tag | null> {
    try {
      return await Database.PRISMA.tag.findFirst({
        where: {
          OR: [
            { name: query },
            { aliases: { has: query } },
            { name: { contains: query } }
          ]
        }
      });
    } catch (e) {
      return null;
    }
  }
Example #3
Source File: tag.ts    From Mandroc with GNU General Public License v3.0 6 votes vote down vote up
/**
 * React-esque hooks for tags.
 *
 * @param query Name or alias of the tag.
 */
export async function useTag(query: string): Promise<TagHook> {
  const tag = await Database.findTag(query);
  if (!tag) {
    return [ null, async () => void 0 ];
  }

  const o_o = new Proxy<Tag>(tag, {
    get: (_, p: PropertyKey): any => Reflect.get(tag, p),
    has: (_, p: PropertyKey): boolean => Reflect.has(tag, p),
    set(_, __, ___): boolean {
      throw new Error("Setting a hook value is not allowed, use the caching update method instead");
    }
  });

  return [ o_o, cachedTagUpdate(tag?.id!!) ];
}
Example #4
Source File: TagResolver.ts    From Mandroc with GNU General Public License v3.0 5 votes vote down vote up
async exec(message: Message, phrase?: string | null): Promise<Tag | Flag | null> {
    if (!message.guild || !phrase) {
      return Flag.fail(phrase);
    }

    return await Database.findTag(phrase);
  }