Skip to content

Commit

Permalink
♻️ refactor: move server modules (lobehub#3291)
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx authored and ipoly committed Jul 29, 2024
1 parent 904814a commit dc362bc
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/database/server/models/__tests__/user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

import { INBOX_SESSION_ID } from '@/const/session';
import { getTestDBInstance } from '@/database/server/core/dbForTest';
import { KeyVaultsGateKeeper } from '@/server/keyVaultsEncrypt';
import { KeyVaultsGateKeeper } from '@/server/modules/KeyVaultsEncrypt';
import { UserPreference } from '@/types/user';
import { UserSettings } from '@/types/user/settings';

Expand Down
2 changes: 1 addition & 1 deletion src/database/server/models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { eq } from 'drizzle-orm';
import { DeepPartial } from 'utility-types';

import { serverDB } from '@/database/server/core/db';
import { KeyVaultsGateKeeper } from '@/server/keyVaultsEncrypt';
import { KeyVaultsGateKeeper } from '@/server/modules/KeyVaultsEncrypt';
import { UserPreference } from '@/types/user';
import { UserSettings } from '@/types/user/settings';
import { merge } from '@/utils/merge';
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/server/routers/edge/upload.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { z } from 'zod';

import { passwordProcedure, router } from '@/libs/trpc';
import { S3 } from '@/server/files/s3';
import { S3 } from '@/server/modules/S3';

export const uploadRouter = router({
createS3PreSignedUrl: passwordProcedure
Expand Down
25 changes: 15 additions & 10 deletions src/server/routers/lambda/importer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@ import { TRPCError } from '@trpc/server';
import { z } from 'zod';

import { authedProcedure, router } from '@/libs/trpc';
import { S3 } from '@/server/files/s3';
import { DataImporter } from '@/server/modules/DataImporter';
import { S3 } from '@/server/modules/S3';
import { DataImporterService } from '@/server/services/dataImporter';
import { ImportResults, ImporterEntryData } from '@/types/importer';

const importProcedure = authedProcedure.use(async (opts) => {
const { ctx } = opts;
const dataImporterService = new DataImporterService(ctx.userId);

return opts.next({
ctx: { dataImporterService },
});
});

export const importerRouter = router({
importByFile: authedProcedure
importByFile: importProcedure
.input(z.object({ pathname: z.string() }))
.mutation(async ({ input, ctx }): Promise<ImportResults> => {
let data: ImporterEntryData | undefined;
Expand All @@ -27,12 +36,10 @@ export const importerRouter = router({
});
}

const dataImporter = new DataImporter(ctx.userId);

return dataImporter.importData(data);
return ctx.dataImporterService.importData(data);
}),

importByPost: authedProcedure
importByPost: importProcedure
.input(
z.object({
data: z.object({
Expand All @@ -45,8 +52,6 @@ export const importerRouter = router({
}),
)
.mutation(async ({ input, ctx }): Promise<ImportResults> => {
const dataImporter = new DataImporter(ctx.userId);

return dataImporter.importData(input.data);
return ctx.dataImporterService.importData(input.data);
}),
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { CURRENT_CONFIG_VERSION } from '@/migrations';
import { ImportResult } from '@/services/config';
import { ImporterEntryData } from '@/types/importer';

import { DataImporter } from '../index';
import { DataImporterService } from '../index';
import mockImportData from './fixtures/messages.json';

let serverDB = await getTestDBInstance();
Expand All @@ -28,7 +28,7 @@ vi.mock('@/database/server/core/db', async () => ({
}));

const userId = 'test-user-id';
let importer: DataImporter;
let importer: DataImporterService;

beforeEach(async () => {
await serverDB.delete(users);
Expand All @@ -38,7 +38,7 @@ beforeEach(async () => {
await tx.insert(users).values({ id: userId });
});

importer = new DataImporter(userId);
importer = new DataImporterService(userId);
});

describe('DataImporter', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { ImportResult } from '@/services/config';
import { ImporterEntryData } from '@/types/importer';

export class DataImporter {
export class DataImporterService {
private userId: string;

/**
Expand Down
2 changes: 1 addition & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default defineConfig({
'**/dist/**',
'**/build/**',
'src/database/server/**/**',
'src/server/modules/**/**',
'src/server/services/**/**',
],
globals: true,
server: {
Expand Down

0 comments on commit dc362bc

Please sign in to comment.