@k34a/blog 0.0.14 → 0.0.16
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/dist/cfg.js +2 -3
- package/dist/services/articles.js +10 -10
- package/package.json +1 -1
package/dist/cfg.js
CHANGED
|
@@ -14,20 +14,20 @@ class y {
|
|
|
14
14
|
const { data: t, error: a } = await this.db.from("articles").select("*").eq("slug", e).eq("status", "Published").single();
|
|
15
15
|
if (a)
|
|
16
16
|
return console.error("Error fetching article details:", a.message), null;
|
|
17
|
-
const { data: d, error:
|
|
18
|
-
if (
|
|
17
|
+
const { data: d, error: i } = await this.db.from("tag_articles").select("tag_id").eq("article_id", t.id);
|
|
18
|
+
if (i)
|
|
19
19
|
return console.error(
|
|
20
20
|
"Error fetching article tag links:",
|
|
21
|
-
|
|
21
|
+
i.message
|
|
22
22
|
), { ...t, tags: [] };
|
|
23
|
-
const n = d?.map((
|
|
23
|
+
const n = d?.map((o) => o.tag_id) || [];
|
|
24
24
|
let r = [];
|
|
25
25
|
if (n.length > 0) {
|
|
26
|
-
const { data:
|
|
26
|
+
const { data: o, error: c } = await this.db.from("tags").select("name").in("id", n);
|
|
27
27
|
c ? console.error(
|
|
28
28
|
"Error fetching article tag names:",
|
|
29
29
|
c.message
|
|
30
|
-
) : r =
|
|
30
|
+
) : r = o.map((l) => l.name);
|
|
31
31
|
}
|
|
32
32
|
return { ...t, tags: r };
|
|
33
33
|
}
|
|
@@ -52,11 +52,11 @@ class y {
|
|
|
52
52
|
* Paginated list of articles with filters and sorting.
|
|
53
53
|
*/
|
|
54
54
|
async list(e) {
|
|
55
|
-
const { page: t, search: a, sortBy: d, tags:
|
|
55
|
+
const { page: t, search: a, sortBy: d, tags: i } = e, n = u[d] ?? u.latest;
|
|
56
56
|
let r = this.db.from("article_with_tags").select("*", { count: "exact" }).eq("status", "Published");
|
|
57
|
-
a && (r = r.ilike("title", `%${a}%`)),
|
|
58
|
-
const
|
|
59
|
-
r = r.range(
|
|
57
|
+
a && (r = r.ilike("title", `%${a}%`)), i && i.length > 0 && (r = r.in("tag", i)), r = r.order(n.column, { ascending: n.ascending });
|
|
58
|
+
const o = t * f, c = o + f - 1;
|
|
59
|
+
console.log({ from: o, to: c }), r = r.range(o, c);
|
|
60
60
|
const { data: l, error: m, count: h } = await r;
|
|
61
61
|
if (console.log({ data: l, error: m, count: h }), m)
|
|
62
62
|
return console.error("Error fetching articles:", m), { items: [], total: 0 };
|