@unchainedshop/core-currencies 2.14.2 → 3.0.0-alpha3
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.
- package/lib/currencies-index.d.ts +2 -1
- package/lib/currencies-index.d.ts.map +1 -1
- package/lib/currencies-index.js +2 -1
- package/lib/currencies-index.js.map +1 -1
- package/lib/db/CurrenciesCollection.d.ts +1 -1
- package/lib/db/CurrenciesCollection.d.ts.map +1 -1
- package/lib/module/configureCurrenciesModule.d.ts +21 -2
- package/lib/module/configureCurrenciesModule.d.ts.map +1 -1
- package/lib/module/configureCurrenciesModule.js +17 -13
- package/lib/module/configureCurrenciesModule.js.map +1 -1
- package/lib/types.d.ts +14 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +2 -0
- package/lib/types.js.map +1 -0
- package/package.json +5 -7
- package/src/currencies-index.ts +2 -1
- package/src/db/CurrenciesCollection.ts +1 -1
- package/src/module/configureCurrenciesModule.ts +38 -20
- package/src/types.ts +15 -0
- package/lib/db/CurrenciesSchema.d.ts +0 -3
- package/lib/db/CurrenciesSchema.d.ts.map +0 -1
- package/lib/db/CurrenciesSchema.js +0 -10
- package/lib/db/CurrenciesSchema.js.map +0 -1
- package/src/db/CurrenciesSchema.ts +0 -13
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"currencies-index.d.ts","sourceRoot":"","sources":["../src/currencies-index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"currencies-index.d.ts","sourceRoot":"","sources":["../src/currencies-index.ts"],"names":[],"mappings":"AAAA,cAAc,uCAAuC,CAAC;AACtD,cAAc,YAAY,CAAC"}
|
package/lib/currencies-index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"currencies-index.js","sourceRoot":"","sources":["../src/currencies-index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"currencies-index.js","sourceRoot":"","sources":["../src/currencies-index.ts"],"names":[],"mappings":"AAAA,cAAc,uCAAuC,CAAC;AACtD,cAAc,YAAY,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { mongodb } from '@unchainedshop/mongodb';
|
|
2
|
-
import { Currency } from '@unchainedshop/
|
|
2
|
+
import { Currency } from '@unchainedshop/core-currencies';
|
|
3
3
|
export declare const CurrenciesCollection: (db: mongodb.Db) => Promise<mongodb.Collection<Currency>>;
|
|
4
4
|
//# sourceMappingURL=CurrenciesCollection.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CurrenciesCollection.d.ts","sourceRoot":"","sources":["../../src/db/CurrenciesCollection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAkB,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"CurrenciesCollection.d.ts","sourceRoot":"","sources":["../../src/db/CurrenciesCollection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAkB,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAE1D,eAAO,MAAM,oBAAoB,OAAc,OAAO,CAAC,EAAE,0CAuBxD,CAAC"}
|
|
@@ -1,5 +1,24 @@
|
|
|
1
|
-
import { ModuleInput } from '@unchainedshop/
|
|
2
|
-
import {
|
|
1
|
+
import { ModuleInput } from '@unchainedshop/core';
|
|
2
|
+
import { Currency, CurrencyQuery } from '../types.js';
|
|
3
|
+
import { SortOption } from '@unchainedshop/utils';
|
|
4
|
+
export type CurrenciesModule = {
|
|
5
|
+
findCurrency: (params: {
|
|
6
|
+
currencyId?: string;
|
|
7
|
+
isoCode?: string;
|
|
8
|
+
}) => Promise<Currency>;
|
|
9
|
+
findCurrencies: (params: CurrencyQuery & {
|
|
10
|
+
limit?: number;
|
|
11
|
+
offset?: number;
|
|
12
|
+
sort?: Array<SortOption>;
|
|
13
|
+
}) => Promise<Array<Currency>>;
|
|
14
|
+
count: (query: CurrencyQuery) => Promise<number>;
|
|
15
|
+
currencyExists: (params: {
|
|
16
|
+
currencyId: string;
|
|
17
|
+
}) => Promise<boolean>;
|
|
18
|
+
update: (_id: string, doc: Currency) => Promise<string>;
|
|
19
|
+
delete: (_id: string) => Promise<number>;
|
|
20
|
+
create: (doc: Currency) => Promise<string | null>;
|
|
21
|
+
};
|
|
3
22
|
export declare const buildFindSelector: ({ includeInactive, contractAddress, queryString, }: CurrencyQuery) => {
|
|
4
23
|
isActive?: true;
|
|
5
24
|
deleted: null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configureCurrenciesModule.d.ts","sourceRoot":"","sources":["../../src/module/configureCurrenciesModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"configureCurrenciesModule.d.ts","sourceRoot":"","sources":["../../src/module/configureCurrenciesModule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGtD,OAAO,EAAiB,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAKjE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,YAAY,EAAE,CAAC,MAAM,EAAE;QAAE,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IACvF,cAAc,EAAE,CACd,MAAM,EAAE,aAAa,GAAG;QACtB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC;KAC1B,KACE,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC9B,KAAK,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACjD,cAAc,EAAE,CAAC,MAAM,EAAE;QAAE,UAAU,EAAE,MAAM,CAAA;KAAE,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACrE,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACxD,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACzC,MAAM,EAAE,CAAC,GAAG,EAAE,QAAQ,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;CACnD,CAAC;AAEF,eAAO,MAAM,iBAAiB,uDAI3B,aAAa;eACe,IAAI;aAAW,IAAI;sBAAoB,MAAM;YAAU,GAAG;CAOxF,CAAC;AAEF,eAAO,MAAM,yBAAyB,YAEnC,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,KAAG,OAAO,CAAC,gBAAgB,CAyE/D,CAAC"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { emit, registerEvents } from '@unchainedshop/events';
|
|
2
|
-
import {
|
|
3
|
-
import { SortDirection } from '@unchainedshop/
|
|
2
|
+
import { generateDbFilterById, buildSortOptions, generateDbObjectId } from '@unchainedshop/mongodb';
|
|
3
|
+
import { SortDirection } from '@unchainedshop/utils';
|
|
4
4
|
import { CurrenciesCollection } from '../db/CurrenciesCollection.js';
|
|
5
|
-
import { CurrenciesSchema } from '../db/CurrenciesSchema.js';
|
|
6
5
|
const CURRENCY_EVENTS = ['CURRENCY_CREATE', 'CURRENCY_UPDATE', 'CURRENCY_REMOVE'];
|
|
7
6
|
export const buildFindSelector = ({ includeInactive = false, contractAddress, queryString, }) => {
|
|
8
7
|
const selector = {
|
|
@@ -19,7 +18,6 @@ export const buildFindSelector = ({ includeInactive = false, contractAddress, qu
|
|
|
19
18
|
export const configureCurrenciesModule = async ({ db, }) => {
|
|
20
19
|
registerEvents(CURRENCY_EVENTS);
|
|
21
20
|
const Currencies = await CurrenciesCollection(db);
|
|
22
|
-
const mutations = generateDbMutations(Currencies, CurrenciesSchema);
|
|
23
21
|
return {
|
|
24
22
|
findCurrency: async ({ currencyId, isoCode }) => {
|
|
25
23
|
return Currencies.findOne(currencyId ? generateDbFilterById(currencyId) : { isoCode });
|
|
@@ -45,7 +43,9 @@ export const configureCurrenciesModule = async ({ db, }) => {
|
|
|
45
43
|
},
|
|
46
44
|
create: async (doc) => {
|
|
47
45
|
await Currencies.deleteOne({ isoCode: doc.isoCode.toUpperCase(), deleted: { $ne: null } });
|
|
48
|
-
const currencyId = await
|
|
46
|
+
const { insertedId: currencyId } = await Currencies.insertOne({
|
|
47
|
+
_id: generateDbObjectId(),
|
|
48
|
+
created: new Date(),
|
|
49
49
|
...doc,
|
|
50
50
|
isoCode: doc.isoCode.toUpperCase(),
|
|
51
51
|
isActive: true,
|
|
@@ -53,22 +53,26 @@ export const configureCurrenciesModule = async ({ db, }) => {
|
|
|
53
53
|
await emit('CURRENCY_CREATE', { currencyId });
|
|
54
54
|
return currencyId;
|
|
55
55
|
},
|
|
56
|
-
update: async (
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
update: async (currencyId, doc) => {
|
|
57
|
+
await Currencies.updateOne(generateDbFilterById(currencyId), {
|
|
58
|
+
$set: {
|
|
59
|
+
updated: new Date(),
|
|
60
|
+
...doc,
|
|
61
|
+
isoCode: doc.isoCode.toUpperCase(),
|
|
62
|
+
},
|
|
60
63
|
});
|
|
61
64
|
await emit('CURRENCY_UPDATE', { currencyId });
|
|
62
65
|
return currencyId;
|
|
63
66
|
},
|
|
64
67
|
delete: async (currencyId) => {
|
|
65
|
-
const deletedCount = await
|
|
68
|
+
const { modifiedCount: deletedCount } = await Currencies.updateOne(generateDbFilterById(currencyId), {
|
|
69
|
+
$set: {
|
|
70
|
+
deleted: new Date(),
|
|
71
|
+
},
|
|
72
|
+
});
|
|
66
73
|
await emit('CURRENCY_REMOVE', { currencyId });
|
|
67
74
|
return deletedCount;
|
|
68
75
|
},
|
|
69
|
-
deletePermanently: async (_id) => {
|
|
70
|
-
return mutations.deletePermanently(_id);
|
|
71
|
-
},
|
|
72
76
|
};
|
|
73
77
|
};
|
|
74
78
|
//# sourceMappingURL=configureCurrenciesModule.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configureCurrenciesModule.js","sourceRoot":"","sources":["../../src/module/configureCurrenciesModule.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"configureCurrenciesModule.js","sourceRoot":"","sources":["../../src/module/configureCurrenciesModule.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACpG,OAAO,EAAE,aAAa,EAAc,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAErE,MAAM,eAAe,GAAa,CAAC,iBAAiB,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,CAAC;AAkB5F,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,EAChC,eAAe,GAAG,KAAK,EACvB,eAAe,EACf,WAAW,GACG,EAAE,EAAE;IAClB,MAAM,QAAQ,GAA8E;QAC1F,OAAO,EAAE,IAAI;KACd,CAAC;IACF,IAAI,CAAC,eAAe;QAAE,QAAQ,CAAC,QAAQ,GAAG,IAAI,CAAC;IAC/C,IAAI,eAAe;QAAE,QAAQ,CAAC,eAAe,GAAG,eAAe,CAAC;IAChE,IAAI,WAAW;QAAE,QAAQ,CAAC,KAAK,GAAG,EAAE,OAAO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,CAAC,SAAS,CAChE,oBAAoB,CAAC,UAAU,CAAC,EAChC;gBACE,IAAI,EAAE;oBACJ,OAAO,EAAE,IAAI,IAAI,EAAE;iBACpB;aACF,CACF,CAAC;YACF,MAAM,IAAI,CAAC,iBAAiB,EAAE,EAAE,UAAU,EAAE,CAAC,CAAC;YAC9C,OAAO,YAAY,CAAC;QACtB,CAAC;KACF,CAAC;AACJ,CAAC,CAAC"}
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { TimestampFields } from '@unchainedshop/mongodb';
|
|
2
|
+
export type Currency = {
|
|
3
|
+
_id?: string;
|
|
4
|
+
isoCode: string;
|
|
5
|
+
isActive: boolean;
|
|
6
|
+
contractAddress?: string;
|
|
7
|
+
decimals?: number;
|
|
8
|
+
} & TimestampFields;
|
|
9
|
+
export type CurrencyQuery = {
|
|
10
|
+
includeInactive?: boolean;
|
|
11
|
+
contractAddress?: string;
|
|
12
|
+
queryString?: string;
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAE9D,MAAM,MAAM,QAAQ,GAAG;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,OAAO,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,GAAG,eAAe,CAAC;AAEpB,MAAM,MAAM,aAAa,GAAG;IAC1B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC"}
|
package/lib/types.js
ADDED
package/lib/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/core-currencies",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-alpha3",
|
|
4
4
|
"main": "lib/currencies-index.js",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./lib/currencies-index.js",
|
|
@@ -31,15 +31,13 @@
|
|
|
31
31
|
},
|
|
32
32
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@unchainedshop/events": "^
|
|
35
|
-
"@unchainedshop/utils": "^
|
|
36
|
-
"simpl-schema": "^3.4.6"
|
|
34
|
+
"@unchainedshop/events": "^3.0.0-alpha3",
|
|
35
|
+
"@unchainedshop/utils": "^3.0.0-alpha3"
|
|
37
36
|
},
|
|
38
37
|
"devDependencies": {
|
|
39
|
-
"@types/node": "^
|
|
40
|
-
"@unchainedshop/types": "^2.14.2",
|
|
38
|
+
"@types/node": "^22.5.5",
|
|
41
39
|
"jest": "^29.7.0",
|
|
42
40
|
"ts-jest": "^29.2.5",
|
|
43
|
-
"typescript": "^5.
|
|
41
|
+
"typescript": "^5.6.2"
|
|
44
42
|
}
|
|
45
43
|
}
|
package/src/currencies-index.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './module/configureCurrenciesModule.js';
|
|
2
|
+
export * from './types.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { mongodb, buildDbIndexes } from '@unchainedshop/mongodb';
|
|
2
|
-
import { Currency } from '@unchainedshop/
|
|
2
|
+
import { Currency } from '@unchainedshop/core-currencies';
|
|
3
3
|
|
|
4
4
|
export const CurrenciesCollection = async (db: mongodb.Db) => {
|
|
5
5
|
const Currencies = db.collection<Currency>('currencies');
|
|
@@ -1,13 +1,28 @@
|
|
|
1
|
-
import { ModuleInput
|
|
2
|
-
import {
|
|
1
|
+
import { ModuleInput } from '@unchainedshop/core';
|
|
2
|
+
import { Currency, CurrencyQuery } from '../types.js';
|
|
3
3
|
import { emit, registerEvents } from '@unchainedshop/events';
|
|
4
|
-
import {
|
|
5
|
-
import { SortDirection, SortOption } from '@unchainedshop/
|
|
4
|
+
import { generateDbFilterById, buildSortOptions, generateDbObjectId } from '@unchainedshop/mongodb';
|
|
5
|
+
import { SortDirection, SortOption } from '@unchainedshop/utils';
|
|
6
6
|
import { CurrenciesCollection } from '../db/CurrenciesCollection.js';
|
|
7
|
-
import { CurrenciesSchema } from '../db/CurrenciesSchema.js';
|
|
8
7
|
|
|
9
8
|
const CURRENCY_EVENTS: string[] = ['CURRENCY_CREATE', 'CURRENCY_UPDATE', 'CURRENCY_REMOVE'];
|
|
10
9
|
|
|
10
|
+
export type CurrenciesModule = {
|
|
11
|
+
findCurrency: (params: { currencyId?: string; isoCode?: string }) => Promise<Currency>;
|
|
12
|
+
findCurrencies: (
|
|
13
|
+
params: CurrencyQuery & {
|
|
14
|
+
limit?: number;
|
|
15
|
+
offset?: number;
|
|
16
|
+
sort?: Array<SortOption>;
|
|
17
|
+
},
|
|
18
|
+
) => Promise<Array<Currency>>;
|
|
19
|
+
count: (query: CurrencyQuery) => Promise<number>;
|
|
20
|
+
currencyExists: (params: { currencyId: string }) => Promise<boolean>;
|
|
21
|
+
update: (_id: string, doc: Currency) => Promise<string>;
|
|
22
|
+
delete: (_id: string) => Promise<number>;
|
|
23
|
+
create: (doc: Currency) => Promise<string | null>;
|
|
24
|
+
};
|
|
25
|
+
|
|
11
26
|
export const buildFindSelector = ({
|
|
12
27
|
includeInactive = false,
|
|
13
28
|
contractAddress,
|
|
@@ -29,11 +44,6 @@ export const configureCurrenciesModule = async ({
|
|
|
29
44
|
|
|
30
45
|
const Currencies = await CurrenciesCollection(db);
|
|
31
46
|
|
|
32
|
-
const mutations = generateDbMutations<Currency>(
|
|
33
|
-
Currencies,
|
|
34
|
-
CurrenciesSchema,
|
|
35
|
-
) as ModuleMutations<Currency>;
|
|
36
|
-
|
|
37
47
|
return {
|
|
38
48
|
findCurrency: async ({ currencyId, isoCode }) => {
|
|
39
49
|
return Currencies.findOne(currencyId ? generateDbFilterById(currencyId) : { isoCode });
|
|
@@ -66,7 +76,9 @@ export const configureCurrenciesModule = async ({
|
|
|
66
76
|
|
|
67
77
|
create: async (doc: Currency) => {
|
|
68
78
|
await Currencies.deleteOne({ isoCode: doc.isoCode.toUpperCase(), deleted: { $ne: null } });
|
|
69
|
-
const currencyId = await
|
|
79
|
+
const { insertedId: currencyId } = await Currencies.insertOne({
|
|
80
|
+
_id: generateDbObjectId(),
|
|
81
|
+
created: new Date(),
|
|
70
82
|
...doc,
|
|
71
83
|
isoCode: doc.isoCode.toUpperCase(),
|
|
72
84
|
isActive: true,
|
|
@@ -75,23 +87,29 @@ export const configureCurrenciesModule = async ({
|
|
|
75
87
|
return currencyId;
|
|
76
88
|
},
|
|
77
89
|
|
|
78
|
-
update: async (
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
90
|
+
update: async (currencyId: string, doc: Partial<Currency>) => {
|
|
91
|
+
await Currencies.updateOne(generateDbFilterById(currencyId), {
|
|
92
|
+
$set: {
|
|
93
|
+
updated: new Date(),
|
|
94
|
+
...doc,
|
|
95
|
+
isoCode: doc.isoCode.toUpperCase(),
|
|
96
|
+
},
|
|
82
97
|
});
|
|
83
98
|
await emit('CURRENCY_UPDATE', { currencyId });
|
|
84
99
|
return currencyId;
|
|
85
100
|
},
|
|
86
101
|
|
|
87
102
|
delete: async (currencyId) => {
|
|
88
|
-
const deletedCount = await
|
|
103
|
+
const { modifiedCount: deletedCount } = await Currencies.updateOne(
|
|
104
|
+
generateDbFilterById(currencyId),
|
|
105
|
+
{
|
|
106
|
+
$set: {
|
|
107
|
+
deleted: new Date(),
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
);
|
|
89
111
|
await emit('CURRENCY_REMOVE', { currencyId });
|
|
90
112
|
return deletedCount;
|
|
91
113
|
},
|
|
92
|
-
|
|
93
|
-
deletePermanently: async (_id) => {
|
|
94
|
-
return mutations.deletePermanently(_id);
|
|
95
|
-
},
|
|
96
114
|
};
|
|
97
115
|
};
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { TimestampFields } from '@unchainedshop/mongodb';
|
|
2
|
+
|
|
3
|
+
export type Currency = {
|
|
4
|
+
_id?: string;
|
|
5
|
+
isoCode: string;
|
|
6
|
+
isActive: boolean;
|
|
7
|
+
contractAddress?: string;
|
|
8
|
+
decimals?: number;
|
|
9
|
+
} & TimestampFields;
|
|
10
|
+
|
|
11
|
+
export type CurrencyQuery = {
|
|
12
|
+
includeInactive?: boolean;
|
|
13
|
+
contractAddress?: string;
|
|
14
|
+
queryString?: string;
|
|
15
|
+
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CurrenciesSchema.d.ts","sourceRoot":"","sources":["../../src/db/CurrenciesSchema.ts"],"names":[],"mappings":"AACA,OAAO,YAAY,MAAM,cAAc,CAAC;AAExC,eAAO,MAAM,gBAAgB,cAS5B,CAAC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { Schemas } from '@unchainedshop/utils';
|
|
2
|
-
import SimpleSchema from 'simpl-schema';
|
|
3
|
-
export const CurrenciesSchema = new SimpleSchema({
|
|
4
|
-
isoCode: { type: String, required: true },
|
|
5
|
-
isActive: Boolean,
|
|
6
|
-
contractAddress: { type: String, required: false },
|
|
7
|
-
decimals: { type: Number, required: false },
|
|
8
|
-
...Schemas.timestampFields,
|
|
9
|
-
}, { requiredByDefault: false });
|
|
10
|
-
//# sourceMappingURL=CurrenciesSchema.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CurrenciesSchema.js","sourceRoot":"","sources":["../../src/db/CurrenciesSchema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,YAAY,MAAM,cAAc,CAAC;AAExC,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,YAAY,CAC9C;IACE,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;IACzC,QAAQ,EAAE,OAAO;IACjB,eAAe,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE;IAClD,QAAQ,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE;IAC3C,GAAG,OAAO,CAAC,eAAe;CAC3B,EACD,EAAE,iBAAiB,EAAE,KAAK,EAAE,CAC7B,CAAC"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Schemas } from '@unchainedshop/utils';
|
|
2
|
-
import SimpleSchema from 'simpl-schema';
|
|
3
|
-
|
|
4
|
-
export const CurrenciesSchema = new SimpleSchema(
|
|
5
|
-
{
|
|
6
|
-
isoCode: { type: String, required: true },
|
|
7
|
-
isActive: Boolean,
|
|
8
|
-
contractAddress: { type: String, required: false },
|
|
9
|
-
decimals: { type: Number, required: false },
|
|
10
|
-
...Schemas.timestampFields,
|
|
11
|
-
},
|
|
12
|
-
{ requiredByDefault: false },
|
|
13
|
-
);
|