Adding a ton of stuff

This commit is contained in:
2026-07-17 04:39:18 -07:00
parent 8d9fe8e75d
commit de28a67417
63 changed files with 2027 additions and 613 deletions
+8 -8
View File
@@ -45,25 +45,25 @@ export abstract class BaseModel<
// identifier: unknown,
// options?: FindByPkOptions<M>,
// ): Promise<M | null>;
public static async findByIdentifierOrPk<M extends BaseModel>(
public static async findBySlugOrPk<M extends BaseModel>(
this: ModelStatic<M>,
identifierOrPk: string | number,
slugOrPk: unknown,
options?: Omit<FindOptions<Attributes<M>>, "where">
): Promise<M | null> {
if (typeof identifierOrPk === "number" || !isNaN(Number(identifierOrPk))) {
const primaryKey = identifierOrPk
if (typeof slugOrPk === "number" || !isNaN(Number(slugOrPk))) {
const primaryKey = slugOrPk
return this.findByPk(primaryKey, options)
}
const identifier = identifierOrPk
if (!("identifier" in this.getAttributes())) {
throw new Error(`${this.name} does not have a 'identifier' attribute.`)
const slug = slugOrPk
if (!("slug" in this.getAttributes())) {
throw new Error(`${this.name} does not have a 'slug' attribute.`)
}
return this.findOne({
...options,
// @ts-expect-error - We know that the model has a slug attribute, and are ignoring the TS error
where: { identifier },
where: { slug },
})
}