mirror of
https://github.com/BradNut/TofuStack
synced 2025-09-08 17:40:26 +00:00
simplified/combined types and interfaces
This commit is contained in:
parent
53ebe9a157
commit
b7a081a941
8 changed files with 12 additions and 14 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
import * as envs from '$env/static/private';
|
import * as envs from '$env/static/private';
|
||||||
import type { Config } from './types/config.type';
|
import type { Config } from './types/config';
|
||||||
|
|
||||||
export const config: Config = {
|
export const config: Config = {
|
||||||
isProduction: envs.NODE_ENV === 'production',
|
isProduction: envs.NODE_ENV === 'production',
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import { Hono } from 'hono';
|
||||||
import { hc } from 'hono/client';
|
import { hc } from 'hono/client';
|
||||||
import { container } from 'tsyringe';
|
import { container } from 'tsyringe';
|
||||||
import { IamController } from './controllers/iam.controller';
|
import { IamController } from './controllers/iam.controller';
|
||||||
import { config, env } from './common/config';
|
import { config } from './common/config';
|
||||||
import { validateAuthSession, verifyOrigin } from './middlewares/auth.middleware';
|
import { validateAuthSession, verifyOrigin } from './middlewares/auth.middleware';
|
||||||
import { AuthCleanupJobs } from './jobs/auth-cleanup.job';
|
import { AuthCleanupJobs } from './jobs/auth-cleanup.job';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,14 +4,14 @@ import { emailVerificationsTable } from "../databases/postgres/tables";
|
||||||
import { takeFirst, takeFirstOrThrow } from "../common/utils/repository";
|
import { takeFirst, takeFirstOrThrow } from "../common/utils/repository";
|
||||||
import { DrizzleService } from "../services/drizzle.service";
|
import { DrizzleService } from "../services/drizzle.service";
|
||||||
|
|
||||||
export type CreateEmailVerification = Pick<InferInsertModel<typeof emailVerificationsTable>, 'requestedEmail' | 'hashedToken' | 'userId' | 'expiresAt'>;
|
type Create = Pick<InferInsertModel<typeof emailVerificationsTable>, 'requestedEmail' | 'hashedToken' | 'userId' | 'expiresAt'>;
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class EmailVerificationsRepository {
|
export class EmailVerificationsRepository {
|
||||||
constructor(@inject(DrizzleService) private readonly drizzle: DrizzleService) { }
|
constructor(@inject(DrizzleService) private readonly drizzle: DrizzleService) { }
|
||||||
|
|
||||||
// creates a new email verification record or updates an existing one
|
// creates a new email verification record or updates an existing one
|
||||||
async create(data: CreateEmailVerification) {
|
async create(data: Create) {
|
||||||
return this.drizzle.db.insert(emailVerificationsTable).values(data).onConflictDoUpdate({
|
return this.drizzle.db.insert(emailVerificationsTable).values(data).onConflictDoUpdate({
|
||||||
target: emailVerificationsTable.userId,
|
target: emailVerificationsTable.userId,
|
||||||
set: data
|
set: data
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,7 @@ import { loginRequestsTable } from "../databases/postgres/tables";
|
||||||
import { takeFirst, takeFirstOrThrow } from "../common/utils/repository";
|
import { takeFirst, takeFirstOrThrow } from "../common/utils/repository";
|
||||||
import { DrizzleService } from "../services/drizzle.service";
|
import { DrizzleService } from "../services/drizzle.service";
|
||||||
|
|
||||||
|
type Create = Pick<InferInsertModel<typeof loginRequestsTable>, 'email' | 'expiresAt' | 'hashedToken'>;
|
||||||
export type CreateLoginRequest = Pick<InferInsertModel<typeof loginRequestsTable>, 'email' | 'expiresAt' | 'hashedToken'>;
|
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class LoginRequestsRepository {
|
export class LoginRequestsRepository {
|
||||||
|
|
@ -13,7 +12,7 @@ export class LoginRequestsRepository {
|
||||||
@inject(DrizzleService) private readonly drizzle: DrizzleService,
|
@inject(DrizzleService) private readonly drizzle: DrizzleService,
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
async create(data: CreateLoginRequest, db = this.drizzle.db) {
|
async create(data: Create, db = this.drizzle.db) {
|
||||||
return db.insert(loginRequestsTable).values(data).onConflictDoUpdate({
|
return db.insert(loginRequestsTable).values(data).onConflictDoUpdate({
|
||||||
target: loginRequestsTable.email,
|
target: loginRequestsTable.email,
|
||||||
set: data
|
set: data
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,10 @@ import { inject, injectable } from 'tsyringe';
|
||||||
import { usersTable } from '../databases/postgres/tables';
|
import { usersTable } from '../databases/postgres/tables';
|
||||||
import { eq, type InferInsertModel } from 'drizzle-orm';
|
import { eq, type InferInsertModel } from 'drizzle-orm';
|
||||||
import { takeFirstOrThrow } from '../common/utils/repository';
|
import { takeFirstOrThrow } from '../common/utils/repository';
|
||||||
import type { Repository } from '../common/inferfaces/repository.interface';
|
|
||||||
import { DrizzleService } from '../services/drizzle.service';
|
import { DrizzleService } from '../services/drizzle.service';
|
||||||
|
|
||||||
export type CreateUser = InferInsertModel<typeof usersTable>;
|
export type Create = InferInsertModel<typeof usersTable>;
|
||||||
export type UpdateUser = Partial<CreateUser>;
|
export type Update = Partial<Create>;
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class UsersRepository {
|
export class UsersRepository {
|
||||||
|
|
@ -30,11 +29,11 @@ export class UsersRepository {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(data: CreateUser, db = this.drizzle.db) {
|
async create(data: Create, db = this.drizzle.db) {
|
||||||
return db.insert(usersTable).values(data).returning().then(takeFirstOrThrow);
|
return db.insert(usersTable).values(data).returning().then(takeFirstOrThrow);
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(id: string, data: UpdateUser, db = this.drizzle.db) {
|
async update(id: string, data: Update, db = this.drizzle.db) {
|
||||||
return db
|
return db
|
||||||
.update(usersTable)
|
.update(usersTable)
|
||||||
.set(data)
|
.set(data)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { injectable } from 'tsyringe';
|
import { injectable } from 'tsyringe';
|
||||||
import type { Email } from '../common/inferfaces/email.interface';
|
|
||||||
import { config } from '../common/config';
|
import { config } from '../common/config';
|
||||||
|
import type { Email } from '../common/types/email';
|
||||||
|
|
||||||
type SendProps = {
|
type SendProps = {
|
||||||
to: string | string[];
|
to: string | string[];
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import { createClient, type RedisClientType } from "redis";
|
import { createClient, type RedisClientType } from "redis";
|
||||||
import { injectable, type Disposable } from "tsyringe";
|
import { injectable, type Disposable } from "tsyringe";
|
||||||
import { config } from "../common/config";
|
import { config } from "../common/config";
|
||||||
import type { AsyncService } from "../common/inferfaces/async-service.interface";
|
import type { AsyncService } from "../common/types/async-service";
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class RedisService implements Disposable, AsyncService {
|
export class RedisService implements Disposable, AsyncService {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue