@unchainedshop/core-bookmarks 2.9.3 → 2.10.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.
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
const hashBookmark = (bookmark) => {
|
|
2
2
|
return `${bookmark.productId}:${bookmark.userId}:${JSON.stringify(bookmark.meta || {})}`;
|
|
3
3
|
};
|
|
4
|
-
export const migrateBookmarksService = async ({
|
|
5
|
-
const fromBookmarks = await modules.bookmarks.findBookmarks({ userId:
|
|
4
|
+
export const migrateBookmarksService = async ({ fromUserId, toUserId, shouldMerge }, { modules }) => {
|
|
5
|
+
const fromBookmarks = await modules.bookmarks.findBookmarks({ userId: fromUserId });
|
|
6
6
|
if (!fromBookmarks) {
|
|
7
7
|
// No bookmarks no copy needed
|
|
8
8
|
return;
|
|
9
9
|
}
|
|
10
10
|
if (!shouldMerge) {
|
|
11
|
-
await modules.bookmarks.deleteByUserId(
|
|
12
|
-
await modules.bookmarks.replaceUserId(
|
|
11
|
+
await modules.bookmarks.deleteByUserId(toUserId);
|
|
12
|
+
await modules.bookmarks.replaceUserId(fromUserId, toUserId);
|
|
13
13
|
}
|
|
14
14
|
else {
|
|
15
|
-
const toBookmarks = await modules.bookmarks.findBookmarks({ userId:
|
|
15
|
+
const toBookmarks = await modules.bookmarks.findBookmarks({ userId: toUserId });
|
|
16
16
|
const toBookmarkHashes = toBookmarks.map(hashBookmark);
|
|
17
17
|
const newBookmarkIds = fromBookmarks
|
|
18
18
|
.filter((fromBookmark) => {
|
|
@@ -20,7 +20,7 @@ export const migrateBookmarksService = async ({ fromUser, toUser, shouldMerge },
|
|
|
20
20
|
return !toBookmarkHashes.includes(hash);
|
|
21
21
|
})
|
|
22
22
|
.map((bookmark) => bookmark._id);
|
|
23
|
-
await modules.bookmarks.replaceUserId(
|
|
23
|
+
await modules.bookmarks.replaceUserId(fromUserId, toUserId, newBookmarkIds);
|
|
24
24
|
}
|
|
25
25
|
};
|
|
26
26
|
//# sourceMappingURL=migrateBookmarksService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrateBookmarksService.js","sourceRoot":"","sources":["../../src/service/migrateBookmarksService.ts"],"names":[],"mappings":"AAEA,MAAM,YAAY,GAAG,CAAC,QAAQ,EAAE,EAAE;IAChC,OAAO,GAAG,QAAQ,CAAC,SAAS,IAAI,QAAQ,CAAC,MAAM,IAAI,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,IAAI,EAAE,CAAC,EAAE,CAAC;AAC3F,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAA4B,KAAK,EACnE,EAAE,
|
|
1
|
+
{"version":3,"file":"migrateBookmarksService.js","sourceRoot":"","sources":["../../src/service/migrateBookmarksService.ts"],"names":[],"mappings":"AAEA,MAAM,YAAY,GAAG,CAAC,QAAQ,EAAE,EAAE;IAChC,OAAO,GAAG,QAAQ,CAAC,SAAS,IAAI,QAAQ,CAAC,MAAM,IAAI,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,IAAI,EAAE,CAAC,EAAE,CAAC;AAC3F,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAA4B,KAAK,EACnE,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,EACrC,EAAE,OAAO,EAAE,EACX,EAAE;IACF,MAAM,aAAa,GAAG,MAAM,OAAO,CAAC,SAAS,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC;IACpF,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,8BAA8B;QAC9B,OAAO;IACT,CAAC;IACD,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,MAAM,OAAO,CAAC,SAAS,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;QACjD,MAAM,OAAO,CAAC,SAAS,CAAC,aAAa,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;IAC9D,CAAC;SAAM,CAAC;QACN,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC,SAAS,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;QAChF,MAAM,gBAAgB,GAAG,WAAW,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QACvD,MAAM,cAAc,GAAG,aAAa;aACjC,MAAM,CAAC,CAAC,YAAY,EAAE,EAAE;YACvB,MAAM,IAAI,GAAG,YAAY,CAAC,YAAY,CAAC,CAAC;YACxC,OAAO,CAAC,gBAAgB,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAC1C,CAAC,CAAC;aACD,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QACnC,MAAM,OAAO,CAAC,SAAS,CAAC,aAAa,CAAC,UAAU,EAAE,QAAQ,EAAE,cAAc,CAAC,CAAC;IAC9E,CAAC;AACH,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/core-bookmarks",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.10.0",
|
|
4
4
|
"main": "lib/bookmarks-index.js",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./lib/bookmarks-index.js",
|
|
@@ -31,15 +31,15 @@
|
|
|
31
31
|
},
|
|
32
32
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@unchainedshop/events": "^2.
|
|
35
|
-
"@unchainedshop/utils": "^2.
|
|
34
|
+
"@unchainedshop/events": "^2.10.0",
|
|
35
|
+
"@unchainedshop/utils": "^2.10.0",
|
|
36
36
|
"simpl-schema": "^3.4.6"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@types/node": "^20.12.
|
|
40
|
-
"@unchainedshop/types": "^2.
|
|
39
|
+
"@types/node": "^20.12.13",
|
|
40
|
+
"@unchainedshop/types": "^2.10.0",
|
|
41
41
|
"jest": "^29.7.0",
|
|
42
|
-
"ts-jest": "^29.1.
|
|
42
|
+
"ts-jest": "^29.1.4",
|
|
43
43
|
"typescript": "^5.4.5"
|
|
44
44
|
}
|
|
45
45
|
}
|
|
@@ -5,19 +5,19 @@ const hashBookmark = (bookmark) => {
|
|
|
5
5
|
};
|
|
6
6
|
|
|
7
7
|
export const migrateBookmarksService: MigrateBookmarksService = async (
|
|
8
|
-
{
|
|
8
|
+
{ fromUserId, toUserId, shouldMerge },
|
|
9
9
|
{ modules },
|
|
10
10
|
) => {
|
|
11
|
-
const fromBookmarks = await modules.bookmarks.findBookmarks({ userId:
|
|
11
|
+
const fromBookmarks = await modules.bookmarks.findBookmarks({ userId: fromUserId });
|
|
12
12
|
if (!fromBookmarks) {
|
|
13
13
|
// No bookmarks no copy needed
|
|
14
14
|
return;
|
|
15
15
|
}
|
|
16
16
|
if (!shouldMerge) {
|
|
17
|
-
await modules.bookmarks.deleteByUserId(
|
|
18
|
-
await modules.bookmarks.replaceUserId(
|
|
17
|
+
await modules.bookmarks.deleteByUserId(toUserId);
|
|
18
|
+
await modules.bookmarks.replaceUserId(fromUserId, toUserId);
|
|
19
19
|
} else {
|
|
20
|
-
const toBookmarks = await modules.bookmarks.findBookmarks({ userId:
|
|
20
|
+
const toBookmarks = await modules.bookmarks.findBookmarks({ userId: toUserId });
|
|
21
21
|
const toBookmarkHashes = toBookmarks.map(hashBookmark);
|
|
22
22
|
const newBookmarkIds = fromBookmarks
|
|
23
23
|
.filter((fromBookmark) => {
|
|
@@ -25,6 +25,6 @@ export const migrateBookmarksService: MigrateBookmarksService = async (
|
|
|
25
25
|
return !toBookmarkHashes.includes(hash);
|
|
26
26
|
})
|
|
27
27
|
.map((bookmark) => bookmark._id);
|
|
28
|
-
await modules.bookmarks.replaceUserId(
|
|
28
|
+
await modules.bookmarks.replaceUserId(fromUserId, toUserId, newBookmarkIds);
|
|
29
29
|
}
|
|
30
30
|
};
|