metamigo-common: build, fmt, lint
This commit is contained in:
parent
2a1ced5383
commit
75fb3f84c4
21 changed files with 95 additions and 156 deletions
|
|
@ -1,4 +1,4 @@
|
|||
/* eslint-disable @typescript-eslint/ban-types,@typescript-eslint/no-explicit-any,max-params */
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any,max-params */
|
||||
import * as Boom from "@hapi/boom";
|
||||
import * as Hapi from "@hapi/hapi";
|
||||
import { CrudRepository } from "../records/crud-repository";
|
||||
|
|
@ -33,12 +33,8 @@ export abstract class AbstractCrudController<
|
|||
*/
|
||||
|
||||
abstract repoName: string;
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
abstract paramsIdField = "id";
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
abstract dbDecoration = "db";
|
||||
abstract paramsIdField;
|
||||
abstract dbDecoration;
|
||||
abstract recordType: PgRecordInfo<TUnsavedR, TSavedR, IdKeyT>;
|
||||
|
||||
repo(request: Hapi.Request): CrudRepository<TUnsavedR, TSavedR, IdKeyT> {
|
||||
|
|
@ -206,7 +202,6 @@ export abstract class AbstractCrudController<
|
|||
};
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
||||
export function unboundCrudController<TRecordInfo extends PgRecordInfo>(
|
||||
aRecordType: TRecordInfo
|
||||
) {
|
||||
|
|
@ -229,7 +224,6 @@ export function unboundCrudController<TRecordInfo extends PgRecordInfo>(
|
|||
};
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
||||
export function CrudControllerBase<Rec extends PgRecordInfo>(recordType: Rec) {
|
||||
return unboundCrudController<Rec>(recordType);
|
||||
}
|
||||
|
|
@ -241,53 +235,53 @@ export const crudRoutesFor = (
|
|||
idParam: string,
|
||||
validate: Record<string, Hapi.RouteOptionsValidate>
|
||||
): Hapi.ServerRoute[] => [
|
||||
{
|
||||
method: "POST",
|
||||
path: `${path}`,
|
||||
options: {
|
||||
handler: controller.create,
|
||||
validate: validate.create,
|
||||
description: `Method that creates a new ${name}.`,
|
||||
tags: ["api", name],
|
||||
},
|
||||
{
|
||||
method: "POST",
|
||||
path: `${path}`,
|
||||
options: {
|
||||
handler: controller.create,
|
||||
validate: validate.create,
|
||||
description: `Method that creates a new ${name}.`,
|
||||
tags: ["api", name],
|
||||
},
|
||||
{
|
||||
method: "PUT",
|
||||
path: `${path}/{${idParam}}`,
|
||||
options: {
|
||||
handler: controller.updateById,
|
||||
validate: validate.updateById,
|
||||
description: `Method that updates a ${name} by its id.`,
|
||||
tags: ["api", name],
|
||||
},
|
||||
},
|
||||
{
|
||||
method: "PUT",
|
||||
path: `${path}/{${idParam}}`,
|
||||
options: {
|
||||
handler: controller.updateById,
|
||||
validate: validate.updateById,
|
||||
description: `Method that updates a ${name} by its id.`,
|
||||
tags: ["api", name],
|
||||
},
|
||||
{
|
||||
method: "GET",
|
||||
path: `${path}/{${idParam}}`,
|
||||
options: {
|
||||
handler: controller.getById,
|
||||
validate: validate.getById,
|
||||
description: `Method that gets a ${name} by its id.`,
|
||||
tags: ["api", name],
|
||||
},
|
||||
},
|
||||
{
|
||||
method: "GET",
|
||||
path: `${path}/{${idParam}}`,
|
||||
options: {
|
||||
handler: controller.getById,
|
||||
validate: validate.getById,
|
||||
description: `Method that gets a ${name} by its id.`,
|
||||
tags: ["api", name],
|
||||
},
|
||||
{
|
||||
method: "GET",
|
||||
path: `${path}`,
|
||||
options: {
|
||||
handler: controller.getAll,
|
||||
description: `Method that gets all ${name}s.`,
|
||||
tags: ["api", name],
|
||||
},
|
||||
},
|
||||
{
|
||||
method: "GET",
|
||||
path: `${path}`,
|
||||
options: {
|
||||
handler: controller.getAll,
|
||||
description: `Method that gets all ${name}s.`,
|
||||
tags: ["api", name],
|
||||
},
|
||||
{
|
||||
method: "DELETE",
|
||||
path: `${path}/{${idParam}}`,
|
||||
options: {
|
||||
handler: controller.deleteById,
|
||||
validate: validate.deleteById,
|
||||
description: `Method that deletes a ${name} by its id.`,
|
||||
tags: ["api", name],
|
||||
},
|
||||
},
|
||||
{
|
||||
method: "DELETE",
|
||||
path: `${path}/{${idParam}}`,
|
||||
options: {
|
||||
handler: controller.deleteById,
|
||||
validate: validate.deleteById,
|
||||
description: `Method that deletes a ${name} by its id.`,
|
||||
tags: ["api", name],
|
||||
},
|
||||
];
|
||||
},
|
||||
];
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
/* eslint-disable unicorn/no-null,max-params */
|
||||
import { createHash, randomBytes } from "crypto";
|
||||
import { createHash, randomBytes } from "node:crypto";
|
||||
import type { AdapterInstance } from "next-auth/adapters";
|
||||
import omit from "lodash/omit";
|
||||
import type { IMetamigoRepositories } from "../records";
|
||||
import type { UnsavedAccount, SavedAccount } from "../records/account";
|
||||
import type { UnsavedAccount } from "../records/account";
|
||||
import type { UserId, UnsavedUser, SavedUser } from "../records/user";
|
||||
import type { UnsavedSession, SavedSession } from "../records/session";
|
||||
|
||||
|
|
@ -12,6 +12,7 @@ export const defaultSessionMaxAge = 30 * 24 * 60 * 60 * 1000;
|
|||
// Sessions updated only if session is greater than this value (0 = always)
|
||||
export const defaulteSessionUpdateAge = 24 * 60 * 60 * 1000;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const getCompoundId = (providerId: any, providerAccountId: any) =>
|
||||
createHash("sha256")
|
||||
.update(`${providerId}:${providerAccountId}`)
|
||||
|
|
@ -26,10 +27,10 @@ export class NextAuthAdapter<TRepositories extends IMetamigoRepositories>
|
|||
private repos: TRepositories,
|
||||
private readonly sessionMaxAge = defaultSessionMaxAge,
|
||||
private readonly sessionUpdateAge = defaulteSessionUpdateAge
|
||||
) { }
|
||||
) {}
|
||||
|
||||
async createUser(profile: UnsavedUser): Promise<SavedUser> {
|
||||
// @ts-expect-error
|
||||
// @ts-expect-error Typescript doesn't like lodash's omit()
|
||||
return this.repos.users.upsert(omit(profile, ["isActive", "id"]));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue