Skip to content

Commit

Permalink
Trying to find the smell and possibly found it, also tagged all place…
Browse files Browse the repository at this point in the history
…s to refactor by adding an explicit „import type“
  • Loading branch information
pozylon committed Nov 26, 2024
1 parent 9b2b53c commit 3d35192
Show file tree
Hide file tree
Showing 25 changed files with 38 additions and 47 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EnrollmentData, IEnrollmentAdapter, IEnrollmentDirector } from '../types.js';
import { ProductPlan } from '@unchainedshop/core-products';
import type { ProductPlan } from '@unchainedshop/core-products';
import { log, LogLevel } from '@unchainedshop/logger';
import { BaseDirector } from '@unchainedshop/utils';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ import { EnrollmentStatus } from '../db/EnrollmentStatus.js';
import { EnrollmentDirector } from '../enrollments-index.js';
import { enrollmentsSettings, EnrollmentsSettingsOptions } from '../enrollments-settings.js';
import { resolveBestCurrency } from '@unchainedshop/utils';
import { Order } from '@unchainedshop/core-orders';
import { OrderPosition } from '@unchainedshop/core-orders';
import { Product } from '@unchainedshop/core-products';
import type { Order, OrderPosition } from '@unchainedshop/core-orders';
import type { Product } from '@unchainedshop/core-products';

// Queries

Expand Down
4 changes: 2 additions & 2 deletions packages/core-enrollments/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IBaseAdapter, IBaseDirector } from '@unchainedshop/utils';
import { TimestampFields, LogFields, Address, Contact } from '@unchainedshop/mongodb';
import { Product, ProductPlan } from '@unchainedshop/core-products';
import { OrderPosition } from '@unchainedshop/core-orders';
import type { Product, ProductPlan } from '@unchainedshop/core-products';
import type { OrderPosition } from '@unchainedshop/core-orders';

export enum EnrollmentStatus {
INITIAL = 'INITIAL',
Expand Down
2 changes: 1 addition & 1 deletion packages/core-filters/src/director/FilterDirector.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { mongodb } from '@unchainedshop/mongodb';
import { Filter, FilterAdapterActions, IFilterAdapter, IFilterDirector } from '../types.js';
import { Product } from '@unchainedshop/core-products';
import type { Product } from '@unchainedshop/core-products';
import { BaseDirector } from '@unchainedshop/utils';

const baseDirector = BaseDirector<IFilterAdapter>('FilterDirector', {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Product } from '@unchainedshop/core-products';
import { mongodb } from '@unchainedshop/mongodb';
import { FilterDirector } from '../director/FilterDirector.js';
import { assortmentFulltextSearch } from '../search/assortmentFulltextSearch.js';
Expand All @@ -16,7 +15,8 @@ import {
SearchProductConfiguration,
} from '../search/search.js';
import { SearchQuery, Filter } from '../types.js';
import { Assortment } from '@unchainedshop/core-assortments';
import type { Assortment } from '@unchainedshop/core-assortments';
import type { Product } from '@unchainedshop/core-products';

export type SearchProducts = {
productsCount: () => Promise<number>;
Expand Down
2 changes: 1 addition & 1 deletion packages/core-filters/src/search/productFulltextSearch.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { mongodb } from '@unchainedshop/mongodb';
import { Product } from '@unchainedshop/core-products';
import type { Product } from '@unchainedshop/core-products';
import { Filter, FilterAdapterActions } from '../types.js';

export const productFulltextSearch = (
Expand Down
4 changes: 2 additions & 2 deletions packages/core-filters/src/search/search.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Filter, SearchQuery } from '../types.js';
import { mongodb } from '@unchainedshop/mongodb';
import { Product } from '@unchainedshop/core-products';
import { Assortment } from '@unchainedshop/core-assortments';
import type { Product } from '@unchainedshop/core-products';
import type { Assortment } from '@unchainedshop/core-assortments';

export type CleanedSearchQuery = Omit<SearchQuery, 'query'> & {
filterQuery: Record<string, Array<string>>;
Expand Down
4 changes: 2 additions & 2 deletions packages/core-filters/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Assortment } from '@unchainedshop/core-assortments';
import type { Assortment } from '@unchainedshop/core-assortments';
import { TimestampFields, mongodb } from '@unchainedshop/mongodb';
import { IBaseAdapter, IBaseDirector } from '@unchainedshop/utils';
import { Product } from '@unchainedshop/core-products';
import type { Product } from '@unchainedshop/core-products';

export enum FilterType {
SWITCH = 'SWITCH',
Expand Down
2 changes: 1 addition & 1 deletion packages/core-orders/src/director/OrderPricingAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BasePricingAdapter, IPricingAdapter, BasePricingAdapterContext } from '@unchainedshop/utils';
import { IOrderPricingSheet, OrderPricingCalculation, OrderPricingSheet } from './OrderPricingSheet.js';
import { Order, OrderDelivery, OrderDiscount, OrderPayment, OrderPosition } from '../types.js';
import { User } from '@unchainedshop/core-users';
import type { User } from '@unchainedshop/core-users';

export interface OrderPricingAdapterContext extends BasePricingAdapterContext {
currency?: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { mongodb, generateDbFilterById, generateDbObjectId } from '@unchainedshop/mongodb';
import { emit, registerEvents } from '@unchainedshop/events';
import { Order, OrderDelivery, OrderDeliveryStatus, OrderDiscount } from '../types.js';
import { DeliveryLocation, IDeliveryPricingSheet } from '@unchainedshop/core-delivery';
import { DeliveryDirector } from '@unchainedshop/core-delivery';
import { type DeliveryLocation, type IDeliveryPricingSheet } from '@unchainedshop/core-delivery';
import { DeliveryDirector } from '@unchainedshop/core-delivery'; // TODO: Important
import { OrderPricingDiscount } from '../director/OrderPricingDirector.js';

export type OrderDeliveriesModule = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { emit, registerEvents } from '@unchainedshop/events';
import { generateDbFilterById, generateDbObjectId, mongodb } from '@unchainedshop/mongodb';
import { Order, OrderDiscount, OrderPayment, OrderPaymentStatus } from '../types.js';
import { IPaymentPricingSheet } from '@unchainedshop/core-payment';
import { OrderPricingDiscount } from '../director/OrderPricingDirector.js';
import type { IPaymentPricingSheet } from '@unchainedshop/core-payment';

export type OrderPaymentsModule = {
// Queries
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { IProductPricingSheet, Product } from '@unchainedshop/core-products';
import { Order, OrderPosition, OrderDiscount, OrderDelivery } from '../types.js';
import { emit, registerEvents } from '@unchainedshop/events';
import { generateDbFilterById, generateDbObjectId, mongodb } from '@unchainedshop/mongodb';
import { ordersSettings } from '../orders-settings.js';
import { OrderPricingDiscount } from '../director/OrderPricingDirector.js';
import type { IProductPricingSheet, Product } from '@unchainedshop/core-products';

export type OrderPositionsModule = {
// Queries
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ export const configureOrderModuleProcessing = ({
const user = await modules.users.findUserById(processedOrder.userId);
const locale = modules.users.userLocale(user);
await services.orders.nextUserCart(
// TODO: This means checkout belongs to services!
{
user,
countryCode: locale.region,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Order, OrderDiscount } from '../types.js';
import { mongodb } from '@unchainedshop/mongodb';
import { PaymentPricingRowCategory } from '@unchainedshop/core-payment';
import {
IOrderPricingSheet,
OrderPricingRowCategory,
OrderPricingSheet,
} from '../director/OrderPricingSheet.js';
import { ProductPricingRowCategory } from '@unchainedshop/core-products';
import { DeliveryPricingRowCategory } from '@unchainedshop/core-delivery';
import { PaymentPricingRowCategory } from '@unchainedshop/core-payment'; // TODO: Important!
import { ProductPricingRowCategory } from '@unchainedshop/core-products'; // TODO: Important!
import { DeliveryPricingRowCategory } from '@unchainedshop/core-delivery'; // TODO: Important!
import { OrderPrice, OrderPricingDiscount } from '../director/OrderPricingDirector.js';

export interface OrderTransformations {
Expand Down
2 changes: 1 addition & 1 deletion packages/core-orders/src/orders-settings.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { generateRandomHash } from '@unchainedshop/utils';
import { Order } from './types.js';
import { Product } from '@unchainedshop/core-products';
import type { Product } from '@unchainedshop/core-products';

export interface OrderSettingsOrderPositionValidation {
order: Order;
Expand Down
2 changes: 1 addition & 1 deletion packages/core-orders/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ProductPricingCalculation } from '@unchainedshop/core-products';
import { TimestampFields, LogFields, Address, Contact } from '@unchainedshop/mongodb';
import { OrderPrice } from './director/OrderPricingDirector.js';
import type { ProductPricingCalculation } from '@unchainedshop/core-products';

export type OrderReport = {
newCount: number;
Expand Down
6 changes: 2 additions & 4 deletions packages/core-payment/src/director/PaymentPricingAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ import {
} from '@unchainedshop/utils';
import { BasePricingAdapter } from '@unchainedshop/utils';
import { PaymentPricingSheet } from './PaymentPricingSheet.js';
import { User } from '@unchainedshop/core-users';
import { OrderPayment } from '@unchainedshop/core-orders';
import { Order } from '@unchainedshop/core-orders';
import { PaymentProvider } from '../types.js';
import { OrderDiscount } from '@unchainedshop/core-orders';
import type { OrderDiscount, OrderPayment, Order } from '@unchainedshop/core-orders';
import type { User } from '@unchainedshop/core-users';

export interface PaymentPricingCalculation extends PricingCalculation {
discountId?: string;
Expand Down
8 changes: 3 additions & 5 deletions packages/core-payment/src/director/PaymentPricingDirector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ import {
PaymentPricingAdapterContext,
PaymentPricingCalculation,
} from './PaymentPricingAdapter.js';
import { BasePricingDirector } from '@unchainedshop/utils';
import { BasePricingDirector, IPricingDirector } from '@unchainedshop/utils';
import { PaymentPricingSheet } from './PaymentPricingSheet.js';
import { User } from '@unchainedshop/core-users';
import { Order } from '@unchainedshop/core-orders';
import { PaymentProvider } from '../types.js';
import { OrderPayment } from '@unchainedshop/core-orders';
import { IPricingDirector } from '@unchainedshop/utils';
import type { OrderPayment, Order } from '@unchainedshop/core-orders';
import type { User } from '@unchainedshop/core-users';

export type PaymentPricingContext =
| {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ import { PaymentPricingContext, PaymentPricingDirector } from '../director/Payme
import { PaymentPricingSheet } from '../director/PaymentPricingSheet.js';
import { PaymentDirector } from '../director/PaymentDirector.js';
import { paymentSettings } from '../payment-settings.js';
import { Order } from '@unchainedshop/core-orders';
import type { Order } from '@unchainedshop/core-orders';
import {
IPaymentPricingSheet,
PaymentPricingCalculation,
PaymentProviderType,
} from '../payment-index.js';
import { PaymentCredentials } from '../db/PaymentCredentialsCollection.js';

export type PaymentProvidersModules = {
// Queries
Expand Down
3 changes: 1 addition & 2 deletions packages/core-payment/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { IBaseAdapter, IBaseDirector } from '@unchainedshop/utils';
import { TimestampFields } from '@unchainedshop/mongodb';
import { Order } from '@unchainedshop/core-orders';
import { OrderPayment } from '@unchainedshop/core-orders';
import type { Order, OrderPayment } from '@unchainedshop/core-orders';

export enum PaymentProviderType {
CARD = 'CARD',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import crypto from 'crypto';
import { Product, ProductConfiguration, IProductPricingSheet, ProductPriceRate } from '../types.js';
import { Currency } from '@unchainedshop/core-currencies';
import { ProductPricingDirector } from '../director/ProductPricingDirector.js';
import { getPriceLevels } from './utils/getPriceLevels.js';
import { getPriceRange } from './utils/getPriceRange.js';
import { ProductPriceRates } from '../db/ProductPriceRates.js';
import { ProductsModule } from '../products-index.js';
import type { Currency } from '@unchainedshop/core-currencies';

export const getDecimals = (originDecimals) => {
if (originDecimals === null || originDecimals === undefined) {
Expand Down
4 changes: 2 additions & 2 deletions packages/core-products/src/module/configureProductsModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ import {
ProductPricingCalculation,
ProductPricingContext,
} from '../types.js';
import { Currency } from '@unchainedshop/core-currencies';
import { OrderPosition } from '@unchainedshop/core-orders';
import type { Currency } from '@unchainedshop/core-currencies';
import type { OrderPosition } from '@unchainedshop/core-orders';

const PRODUCT_EVENTS = [
'PRODUCT_CREATE',
Expand Down
7 changes: 2 additions & 5 deletions packages/core-products/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import { Order } from '@unchainedshop/core-orders';
import { User } from '@unchainedshop/core-users';
import { TimestampFields, mongodb } from '@unchainedshop/mongodb';
import { OrderDiscount } from '@unchainedshop/core-orders';
import { OrderPosition } from '@unchainedshop/core-orders';
import { OrderPrice } from '@unchainedshop/core-orders';
import {
BasePricingAdapterContext,
IPricingAdapter,
IPricingDirector,
IPricingSheet,
PricingCalculation,
} from '@unchainedshop/utils';
import type { Order, OrderDiscount, OrderPosition, OrderPrice } from '@unchainedshop/core-orders';
import type { User } from '@unchainedshop/core-users';

export type ProductMedia = {
_id?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { IWarehousingAdapter, IWarehousingDirector, WarehousingContext } from '.
import { log, LogLevel } from '@unchainedshop/logger';
import { BaseDirector } from '@unchainedshop/utils';
import { WarehousingError } from './WarehousingError.js';
import { DeliveryDirector } from '@unchainedshop/core-delivery';
import { DeliveryDirector } from '@unchainedshop/core-delivery'; // TODO: Important smell!

const getReferenceDate = (context: WarehousingContext) => {
return context && context.referenceDate ? context.referenceDate : new Date();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const updateUserAvatarAfterUploadService: UpdateUserAvatarAfterUploadServ

try {
if (fileIds?.length) {
await services.files.removeFiles(
await removeFilesService(
{
fileIds,
},
Expand Down

0 comments on commit 3d35192

Please sign in to comment.