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 type { Config } from './types/config.type';
|
||||
import type { Config } from './types/config';
|
||||
|
||||
export const config: Config = {
|
||||
isProduction: envs.NODE_ENV === 'production',
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { Hono } from 'hono';
|
|||
import { hc } from 'hono/client';
|
||||
import { container } from 'tsyringe';
|
||||
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 { AuthCleanupJobs } from './jobs/auth-cleanup.job';
|
||||
|
||||
|
|
|
|||
|
|
@ -4,14 +4,14 @@ import { emailVerificationsTable } from "../databases/postgres/tables";
|
|||
import { takeFirst, takeFirstOrThrow } from "../common/utils/repository";
|
||||
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()
|
||||
export class EmailVerificationsRepository {
|
||||
constructor(@inject(DrizzleService) private readonly drizzle: DrizzleService) { }
|
||||
|
||||
// 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({
|
||||
target: emailVerificationsTable.userId,
|
||||
set: data
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@ import { loginRequestsTable } from "../databases/postgres/tables";
|
|||
import { takeFirst, takeFirstOrThrow } from "../common/utils/repository";
|
||||
import { DrizzleService } from "../services/drizzle.service";
|
||||
|
||||
|
||||
export type CreateLoginRequest = Pick<InferInsertModel<typeof loginRequestsTable>, 'email' | 'expiresAt' | 'hashedToken'>;
|
||||
type Create = Pick<InferInsertModel<typeof loginRequestsTable>, 'email' | 'expiresAt' | 'hashedToken'>;
|
||||
|
||||
@injectable()
|
||||
export class LoginRequestsRepository {
|
||||
|
|
@ -13,7 +12,7 @@ export class LoginRequestsRepository {
|
|||
@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({
|
||||
target: loginRequestsTable.email,
|
||||
set: data
|
||||
|
|
|
|||
|
|
@ -2,11 +2,10 @@ import { inject, injectable } from 'tsyringe';
|
|||
import { usersTable } from '../databases/postgres/tables';
|
||||
import { eq, type InferInsertModel } from 'drizzle-orm';
|
||||
import { takeFirstOrThrow } from '../common/utils/repository';
|
||||
import type { Repository } from '../common/inferfaces/repository.interface';
|
||||
import { DrizzleService } from '../services/drizzle.service';
|
||||
|
||||
export type CreateUser = InferInsertModel<typeof usersTable>;
|
||||
export type UpdateUser = Partial<CreateUser>;
|
||||
export type Create = InferInsertModel<typeof usersTable>;
|
||||
export type Update = Partial<Create>;
|
||||
|
||||
@injectable()
|
||||
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);
|
||||
}
|
||||
|
||||
async update(id: string, data: UpdateUser, db = this.drizzle.db) {
|
||||
async update(id: string, data: Update, db = this.drizzle.db) {
|
||||
return db
|
||||
.update(usersTable)
|
||||
.set(data)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { injectable } from 'tsyringe';
|
||||
import type { Email } from '../common/inferfaces/email.interface';
|
||||
import { config } from '../common/config';
|
||||
import type { Email } from '../common/types/email';
|
||||
|
||||
type SendProps = {
|
||||
to: string | string[];
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { createClient, type RedisClientType } from "redis";
|
||||
import { injectable, type Disposable } from "tsyringe";
|
||||
import { config } from "../common/config";
|
||||
import type { AsyncService } from "../common/inferfaces/async-service.interface";
|
||||
import type { AsyncService } from "../common/types/async-service";
|
||||
|
||||
@injectable()
|
||||
export class RedisService implements Disposable, AsyncService {
|
||||
|
|
|
|||
Loading…
Reference in a new issue