@yimingliao/cms 0.0.69 → 0.0.70

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.
@@ -651,7 +651,11 @@ declare function createPostQueryRepository(prisma: PrismaClient): {
651
651
  find: ({ isActive, ...rest }: FindParams) => Promise<(Post & {
652
652
  translations: PostTranslation[];
653
653
  }) | null>;
654
- findFull: ({ isActive, topicSlug, ...rest }: FindParams) => Promise<PostFull | null>;
654
+ findFull: ({ isActive, topicSlug, ...rest }: FindParams) => Promise<{
655
+ post: PostFull | null;
656
+ prev: PostListCard | null;
657
+ next: PostListCard | null;
658
+ }>;
655
659
  };
656
660
 
657
661
  interface UpsertParams {
@@ -2258,7 +2262,11 @@ declare function createPostFindFullAction(ctx: ActionContext): (params: {
2258
2262
  isActive?: boolean;
2259
2263
  topicSlug?: string;
2260
2264
  }) => Promise<Result<{
2261
- post: PostFull;
2265
+ post: {
2266
+ post: PostFull | null;
2267
+ prev: PostListCard | null;
2268
+ next: PostListCard | null;
2269
+ };
2262
2270
  }>>;
2263
2271
 
2264
2272
  declare function createPostFindListCardsAction(ctx: ActionContext): (params: {
@@ -1809,17 +1809,44 @@ function createPostQueryRepository(prisma) {
1809
1809
  ...rest
1810
1810
  }) {
1811
1811
  const where = buildWhere3(rest);
1812
- if (!where) return null;
1813
- return prisma.post.findFirst({
1814
- where: {
1815
- ...where,
1816
- // states
1817
- ...isActive ? { isActive } : {},
1818
- // relations
1819
- ...topicSlug ? { topic: { slug: topicSlug } } : {}
1820
- },
1812
+ if (!where) return { post: null, prev: null, next: null };
1813
+ const baseWhere = {
1814
+ ...where,
1815
+ // states
1816
+ ...isActive ? { isActive } : {},
1817
+ // relations
1818
+ ...topicSlug ? { topic: { slug: topicSlug } } : {}
1819
+ };
1820
+ const post = await prisma.post.findFirst({
1821
+ where: baseWhere,
1821
1822
  include: POST_FULL_INCLUDE
1822
1823
  });
1824
+ if (!post) return { post: null, prev: null, next: null };
1825
+ const next = await prisma.post.findFirst({
1826
+ where: baseWhere,
1827
+ orderBy: POST_ORDER_BY,
1828
+ cursor: { id: post.id },
1829
+ skip: 1,
1830
+ take: 1,
1831
+ include: POST_LIST_CARD_INCLUDE
1832
+ });
1833
+ const reversedOrder = POST_ORDER_BY.map((o) => {
1834
+ const key = Object.keys(o)[0];
1835
+ return { [key]: o[key] === "asc" ? "desc" : "asc" };
1836
+ });
1837
+ const prev = await prisma.post.findFirst({
1838
+ where: baseWhere,
1839
+ orderBy: reversedOrder,
1840
+ cursor: { id: post.id },
1841
+ skip: 1,
1842
+ take: 1,
1843
+ include: POST_LIST_CARD_INCLUDE
1844
+ });
1845
+ return {
1846
+ post,
1847
+ prev,
1848
+ next
1849
+ };
1823
1850
  }
1824
1851
  return {
1825
1852
  findListCards,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yimingliao/cms",
3
- "version": "0.0.69",
3
+ "version": "0.0.70",
4
4
  "author": "Yiming Liao",
5
5
  "license": "MIT",
6
6
  "type": "module",