Skip to content

Commit

Permalink
Move more services
Browse files Browse the repository at this point in the history
  • Loading branch information
pozylon committed Nov 22, 2024
1 parent b79819d commit c736d3d
Show file tree
Hide file tree
Showing 24 changed files with 138 additions and 149 deletions.
2 changes: 1 addition & 1 deletion packages/core-bookmarks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"homepage": "https://github.com/unchainedshop/unchained#readme",
"dependencies": {
"@unchainedshop/events": "^3.0.0-alpha4",
"@unchainedshop/utils": "^3.0.0-alpha4"
"@unchainedshop/mongodb": "^3.0.0-alpha4"
},
"devDependencies": {
"@types/node": "^22.9.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/core-bookmarks/src/bookmarks-index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './module/configureBookmarksModule.js';
export * from './service/bookmarkServices.js';
export * from './db/BookmarksCollection.js';
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { emit, registerEvents } from '@unchainedshop/events';
import { generateDbFilterById, generateDbObjectId, mongodb } from '@unchainedshop/mongodb';
import {
generateDbFilterById,
generateDbObjectId,
mongodb,
TimestampFields,
ModuleInput,
} from '@unchainedshop/mongodb';
import { BookmarksCollection } from '../db/BookmarksCollection.js';
import { TimestampFields, ModuleInput } from '@unchainedshop/mongodb';

const BOOKMARK_EVENTS: string[] = ['BOOKMARK_CREATE', 'BOOKMARK_UPDATE', 'BOOKMARK_REMOVE'];

Expand Down
11 changes: 0 additions & 11 deletions packages/core-bookmarks/src/service/bookmarkServices.ts

This file was deleted.

3 changes: 2 additions & 1 deletion packages/core-files/src/files-index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './types.js';
export * from './module/configureFilesModule.js';
export * from './service/fileServices.js';
export * from './files-settings.js';
export * from './utils/getFileAdapter.js';
export * from './utils/getFileFromFileData.js';
30 changes: 0 additions & 30 deletions packages/core-files/src/service/fileServices.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UploadFileData } from './types.js';
import { UploadFileData } from '@unchainedshop/file-upload';

export const getFileFromFileData = (fileData: UploadFileData, meta: any) => ({
_id: fileData._id,
Expand Down
1 change: 0 additions & 1 deletion packages/core-orders/src/orders-index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export * from './types.js';
export * from './module/configureOrdersModule.js';
export * from './service/orderServices.js';
export * from './orders-settings.js';

export * from './director/OrderDiscountConfiguration.js';
Expand Down
12 changes: 0 additions & 12 deletions packages/core-orders/src/service/orderServices.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"@unchainedshop/core-users": "^3.0.0-alpha4",
"@unchainedshop/core-warehousing": "^3.0.0-alpha4",
"@unchainedshop/core-worker": "^3.0.0-alpha4",
"@unchainedshop/utils": "^3.0.0-alpha4",
"@unchainedshop/logger": "^3.0.0-alpha4"
},
"devDependencies": {
Expand Down
51 changes: 6 additions & 45 deletions packages/core/src/core-index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ import {
AssortmentsSettingsOptions,
configureAssortmentsModule,
} from '@unchainedshop/core-assortments';
import {
BookmarkServices,
bookmarkServices,
BookmarksModule,
configureBookmarksModule,
} from '@unchainedshop/core-bookmarks';
import { BookmarksModule, configureBookmarksModule } from '@unchainedshop/core-bookmarks';
import { configureCountriesModule, CountriesModule } from '@unchainedshop/core-countries';
import { configureCurrenciesModule, CurrenciesModule } from '@unchainedshop/core-currencies';
import {
Expand All @@ -23,36 +18,22 @@ import {
EnrollmentsSettingsOptions,
} from '@unchainedshop/core-enrollments';
import { configureEventsModule, EventsModule } from '@unchainedshop/core-events';
import {
configureFilesModule,
FileServices,
fileServices,
FilesModule,
FilesSettingsOptions,
} from '@unchainedshop/core-files';
import { configureFilesModule, FilesModule, FilesSettingsOptions } from '@unchainedshop/core-files';
import {
configureFiltersModule,
FiltersModule,
FiltersSettingsOptions,
} from '@unchainedshop/core-filters';
import { configureLanguagesModule, LanguagesModule } from '@unchainedshop/core-languages';
import { configureMessagingModule, MessagingModule } from '@unchainedshop/core-messaging';
import {
configureOrdersModule,
OrderServices,
orderServices,
OrdersModule,
OrdersSettingsOptions,
} from '@unchainedshop/core-orders';
import { configureOrdersModule, OrdersModule, OrdersSettingsOptions } from '@unchainedshop/core-orders';
import {
configurePaymentModule,
PaymentModule,
PaymentSettingsOptions,
} from '@unchainedshop/core-payment';
import {
configureProductsModule,
ProductServices,
productServices,
ProductsModule,
ProductsSettingsOptions,
} from '@unchainedshop/core-products';
Expand All @@ -65,9 +46,9 @@ import { configureUsersModule, UserSettingsOptions, UsersModule } from '@unchain
import { configureWarehousingModule, WarehousingModule } from '@unchainedshop/core-warehousing';
import { configureWorkerModule, WorkerModule, WorkerSettingsOptions } from '@unchainedshop/core-worker';
import { mongodb, MigrationRepository, ModuleInput } from '@unchainedshop/mongodb';
import { migrateUserDataService } from './services/migrateUserDataService.js';
import { updateUserAvatarAfterUploadService } from './services/updateUserAvatarAfterUploadService.js';
import defaultServices, { Services } from './services/index.js';

export * from './services/index.js';
export * from './types.js';

export interface ModuleOptions {
Expand Down Expand Up @@ -119,19 +100,6 @@ export interface Modules {
worker: WorkerModule;
}

export interface UserServices {
updateUserAvatarAfterUpload: typeof updateUserAvatarAfterUploadService;
migrateUserData: typeof migrateUserDataService;
}

export interface Services {
bookmarks: BookmarkServices;
files: FileServices;
orders: OrderServices;
products: ProductServices;
users: UserServices;
}

export interface UnchainedCore {
modules: Modules;
services: Services;
Expand Down Expand Up @@ -267,14 +235,7 @@ export const initCore = async ({
...customModules,
},
services: {
bookmarks: bookmarkServices,
files: fileServices,
orders: orderServices,
products: productServices,
users: {
migrateUserData: migrateUserDataService,
updateUserAvatarAfterUpload: updateUserAvatarAfterUploadService,
},
...defaultServices,
...services,
},
bulkImporter,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { getFileAdapter } from '../utils/getFileAdapter.js';
import { Readable } from 'stream';
import { FilesModule } from '../files-index.js';
import { FilesModule, getFileAdapter } from '@unchainedshop/core-files';

export type CreateDownloadStreamService = (
params: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { getFileFromFileData } from '@unchainedshop/file-upload';
import { getFileAdapter } from '../utils/getFileAdapter.js';
import { SignedFileUpload } from '../types.js';
import { FilesModule } from '../files-index.js';
import {
getFileFromFileData,
getFileAdapter,
SignedFileUpload,
FilesModule,
} from '@unchainedshop/core-files';

export type CreateSignedURLService = (
params: { directoryName: string; fileName: string; meta?: any },
Expand Down
67 changes: 67 additions & 0 deletions packages/core/src/services/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { productServices, ProductServices } from '@unchainedshop/core-products';

import { migrateUserDataService } from './migrateUserDataService.js';
import { updateUserAvatarAfterUploadService } from './updateUserAvatarAfterUploadService.js';
import { linkFileService } from './linkFileService.js';
import { createSignedURLService } from './createSignedURLService.js';
import { uploadFileFromURLService } from './uploadFileFromURLService.js';
import { uploadFileFromStreamService } from './uploadFileFromStreamService.js';
import { removeFilesService } from './removeFilesService.js';
import { createDownloadStreamService } from './createDownloadStreamService.js';
import { migrateBookmarksService } from './migrateBookmarksService.js';
import { migrateOrderCartsService } from './migrateOrderCartService.js';
import { nextUserCartService } from './nextUserCartService.js';

export interface UserServices {
updateUserAvatarAfterUpload: typeof updateUserAvatarAfterUploadService;
migrateUserData: typeof migrateUserDataService;
}

export interface FileServices {
linkFile: typeof linkFileService;
uploadFileFromStream: typeof uploadFileFromStreamService;
uploadFileFromURL: typeof uploadFileFromURLService;
createSignedURL: typeof createSignedURLService;
removeFiles: typeof removeFilesService;
createDownloadStream: typeof createDownloadStreamService;
}

export interface BookmarkServices {
migrateBookmarks: typeof migrateBookmarksService;
}

export interface OrderServices {
migrateOrderCarts: typeof migrateOrderCartsService;
nextUserCart: typeof nextUserCartService;
}

export interface Services {
bookmarks: BookmarkServices;
files: FileServices;
orders: OrderServices;
products: ProductServices;
users: UserServices;
}

export default {
bookmarks: {
migrateBookmarks: migrateBookmarksService,
},
files: {
linkFile: linkFileService,
createSignedURL: createSignedURLService,
uploadFileFromURL: uploadFileFromURLService,
uploadFileFromStream: uploadFileFromStreamService,
removeFiles: removeFilesService,
createDownloadStream: createDownloadStreamService,
},
orders: {
migrateOrderCarts: migrateOrderCartsService,
nextUserCart: nextUserCartService,
},
products: productServices,
users: {
migrateUserData: migrateUserDataService,
updateUserAvatarAfterUpload: updateUserAvatarAfterUploadService,
},
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { FileDirector } from '@unchainedshop/file-upload';
import { File } from '../types.js';
import { FilesModule } from '../files-index.js';
import { FilesModule, File } from '@unchainedshop/core-files';

// TODO: Find solution for FileDirector dependency

export type LinkFileService = (
params: { fileId: string; size: number; type?: string },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BookmarksModule } from '../bookmarks-index.js';
import { BookmarksModule } from '@unchainedshop/core-bookmarks';

export type MigrateBookmarksService = (
params: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { UnchainedCore } from '@unchainedshop/core';
import { Order } from '../types.js';
import { Order, OrdersModule } from '@unchainedshop/core-orders';

export type MigrateOrderCartsService = (
params: {
Expand All @@ -8,7 +7,11 @@ export type MigrateOrderCartsService = (
shouldMerge: boolean;
countryContext: string;
},
unchainedAPI: UnchainedCore,
unchainedAPI: {
modules: {
orders: OrdersModule;
};
},
) => Promise<Order>;

export const migrateOrderCartsService: MigrateOrderCartsService = async (
Expand All @@ -32,7 +35,7 @@ export const migrateOrderCartsService: MigrateOrderCartsService = async (
if (!toCart || !shouldMerge) {
// No destination cart, move whole cart
unchainedAPI.modules.orders.setCartOwner({ orderId: fromCart._id, userId: toUserId });
return unchainedAPI.modules.orders.updateCalculation(fromCart._id, unchainedAPI);
return unchainedAPI.modules.orders.updateCalculation(fromCart._id, unchainedAPI as any);
}

// Move positions
Expand All @@ -48,6 +51,6 @@ export const migrateOrderCartsService: MigrateOrderCartsService = async (
await unchainedAPI.modules.orders.updateContact(toCart._id, fromCart.contact);
}

await unchainedAPI.modules.orders.updateCalculation(fromCart._id, unchainedAPI);
return unchainedAPI.modules.orders.updateCalculation(toCart._id, unchainedAPI);
await unchainedAPI.modules.orders.updateCalculation(fromCart._id, unchainedAPI as any);
return unchainedAPI.modules.orders.updateCalculation(toCart._id, unchainedAPI as any);
};
5 changes: 4 additions & 1 deletion packages/core/src/services/migrateUserDataService.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import { userSettings, UsersModule } from '@unchainedshop/core-users';
import { BookmarksModule } from '@unchainedshop/core-bookmarks';
import { migrateBookmarksService } from './migrateBookmarksService.js';

export type MigrateUserDataService = (
userIdBeforeLogin,
userId,
unchainedAPI: {
modules: {
users: UsersModule;
bookmarks: BookmarksModule;
};
services: {
orders: {
migrateOrderCarts: any;
};
bookmarks: {
migrateBookmarks: any;
migrateBookmarks: typeof migrateBookmarksService;
};
};
},
Expand Down
Loading

0 comments on commit c736d3d

Please sign in to comment.