@unchainedshop/core-countries 4.4.0 → 4.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { CountriesCollection } from "../db/CountriesCollection.js";
|
|
2
|
+
export default function convertDefaultCurrencyCode(repository) {
|
|
3
|
+
repository?.register({
|
|
4
|
+
id: 20241220123500,
|
|
5
|
+
name: 'Remove defaultCurrencyId from countries and add defaultCurrencyCode',
|
|
6
|
+
up: async () => {
|
|
7
|
+
const Currencies = await repository.db.collection('currencies');
|
|
8
|
+
const Countries = await CountriesCollection(repository.db);
|
|
9
|
+
const allCurrencies = await Currencies.find({}).toArray();
|
|
10
|
+
const allCountries = await Countries.find({}).toArray();
|
|
11
|
+
const currencyMap = allCurrencies.reduce((acc, currency) => {
|
|
12
|
+
acc[currency._id] = currency.isoCode;
|
|
13
|
+
return acc;
|
|
14
|
+
}, {});
|
|
15
|
+
for (const country of allCountries) {
|
|
16
|
+
await Countries.updateOne({ _id: country._id, defaultCurrencyId: { $exists: true } }, {
|
|
17
|
+
$set: {
|
|
18
|
+
defaultCurrencyCode: currencyMap[country.defaultCurrencyId],
|
|
19
|
+
},
|
|
20
|
+
$unset: {
|
|
21
|
+
defaultCurrencyId: 1,
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
}
|
|
@@ -6,12 +6,13 @@ export type Country = {
|
|
|
6
6
|
isActive?: boolean;
|
|
7
7
|
defaultCurrencyCode?: string;
|
|
8
8
|
} & TimestampFields;
|
|
9
|
-
export
|
|
9
|
+
export interface CountryQuery {
|
|
10
10
|
includeInactive?: boolean;
|
|
11
11
|
queryString?: string;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export declare const
|
|
12
|
+
isoCodes?: string[];
|
|
13
|
+
}
|
|
14
|
+
export declare const buildFindSelector: ({ includeInactive, queryString, isoCodes, }: CountryQuery) => mongodb.Filter<Country>;
|
|
15
|
+
export declare const configureCountriesModule: ({ db, migrationRepository, }: ModuleInput<Record<string, never>>) => Promise<{
|
|
15
16
|
count: (query: CountryQuery) => Promise<number>;
|
|
16
17
|
findCountry: (params: {
|
|
17
18
|
countryId: string;
|
|
@@ -4,18 +4,23 @@ import { generateDbFilterById, buildSortOptions, generateDbObjectId } from '@unc
|
|
|
4
4
|
import { SortDirection } from '@unchainedshop/utils';
|
|
5
5
|
import { systemLocale } from '@unchainedshop/utils';
|
|
6
6
|
import { CountriesCollection } from "../db/CountriesCollection.js";
|
|
7
|
+
import convertDefaultCurrencyCode from "../migrations/20241220123500-default-currency-code.js";
|
|
7
8
|
const COUNTRY_EVENTS = ['COUNTRY_CREATE', 'COUNTRY_UPDATE', 'COUNTRY_REMOVE'];
|
|
8
|
-
export const buildFindSelector = ({ includeInactive = false, queryString = '',
|
|
9
|
-
const selector = {
|
|
9
|
+
export const buildFindSelector = ({ includeInactive = false, queryString = '', isoCodes, }) => {
|
|
10
|
+
const selector = { deleted: null };
|
|
10
11
|
if (!includeInactive)
|
|
11
12
|
selector.isActive = true;
|
|
13
|
+
if (isoCodes) {
|
|
14
|
+
selector.isoCode = { $in: isoCodes };
|
|
15
|
+
}
|
|
12
16
|
if (queryString) {
|
|
13
17
|
assertDocumentDBCompatMode();
|
|
14
18
|
selector.$text = { $search: queryString };
|
|
15
19
|
}
|
|
16
20
|
return selector;
|
|
17
21
|
};
|
|
18
|
-
export const configureCountriesModule = async ({ db }) => {
|
|
22
|
+
export const configureCountriesModule = async ({ db, migrationRepository, }) => {
|
|
23
|
+
convertDefaultCurrencyCode(migrationRepository);
|
|
19
24
|
registerEvents(COUNTRY_EVENTS);
|
|
20
25
|
const Countries = await CountriesCollection(db);
|
|
21
26
|
return {
|
package/package.json
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/core-countries",
|
|
3
|
-
"
|
|
3
|
+
"description": "Country management module for the Unchained Engine",
|
|
4
|
+
"version": "4.6.0",
|
|
4
5
|
"main": "lib/countries-index.js",
|
|
5
6
|
"types": "lib/countries-index.d.ts",
|
|
6
7
|
"type": "module",
|
|
8
|
+
"sideEffects": false,
|
|
7
9
|
"scripts": {
|
|
8
10
|
"clean": "tsc -b --clean",
|
|
9
11
|
"build": "tsc -b",
|
|
@@ -33,8 +35,8 @@
|
|
|
33
35
|
},
|
|
34
36
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
35
37
|
"dependencies": {
|
|
36
|
-
"@unchainedshop/events": "^4.
|
|
37
|
-
"@unchainedshop/utils": "^4.
|
|
38
|
+
"@unchainedshop/events": "^4.6.0",
|
|
39
|
+
"@unchainedshop/utils": "^4.6.0"
|
|
38
40
|
},
|
|
39
41
|
"devDependencies": {
|
|
40
42
|
"@types/node": "^25.0.0",
|