From 13750d1fc803d4fb45c5516b321e3b4a52db29f5 Mon Sep 17 00:00:00 2001 From: unknown <2182025330@QQ.COM> Date: Thu, 31 Oct 2024 14:46:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E4=BA=86=E8=AF=84=E8=AE=BA?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/checkers/essay.ts | 15 +++ src/components/console/likes/index.json | 5 + src/components/console/likes/index.ts | 11 ++ .../console/likes/locales/zh_CN.json | 3 + .../console/likes/styles.module.less | 7 ++ src/components/console/likes/web.pc.tsx | 31 +++++ .../frontend/home/comment/index.json | 5 + src/components/frontend/home/comment/index.ts | 13 +++ .../frontend/home/comment/locales/zh_CN.json | 3 + .../frontend/home/comment/styles.module.less | 36 ++++++ .../frontend/home/comment/web.pc.tsx | 102 +++++++++++++++++ src/data/i18n.ts | 39 ++++++- src/entities/Comment.ts | 24 ++++ src/entities/Essay.ts | 10 +- src/entities/Likes.ts | 37 ++++++ src/features/Console.ts | 15 ++- src/locales/common/zh_CN.json | 107 +++++++++--------- src/locales/menu/zh_CN.json | 3 +- src/pages/console/comment/list/index.json | 5 + src/pages/console/comment/list/index.ts | 20 ++++ .../console/comment/list/locales/zh_CN.json | 6 + .../console/comment/list/styles.module.less | 7 ++ src/pages/console/comment/list/web.pc.tsx | 74 ++++++++++++ src/pages/frontend/essay/details/web.pc.tsx | 8 ++ src/triggers/essay.ts | 55 +++++++++ src/triggers/index.ts | 2 + src/triggers/likes.ts | 35 ++++++ 27 files changed, 618 insertions(+), 60 deletions(-) create mode 100644 src/components/console/likes/index.json create mode 100644 src/components/console/likes/index.ts create mode 100644 src/components/console/likes/locales/zh_CN.json create mode 100644 src/components/console/likes/styles.module.less create mode 100644 src/components/console/likes/web.pc.tsx create mode 100644 src/components/frontend/home/comment/index.json create mode 100644 src/components/frontend/home/comment/index.ts create mode 100644 src/components/frontend/home/comment/locales/zh_CN.json create mode 100644 src/components/frontend/home/comment/styles.module.less create mode 100644 src/components/frontend/home/comment/web.pc.tsx create mode 100644 src/entities/Comment.ts create mode 100644 src/entities/Likes.ts create mode 100644 src/pages/console/comment/list/index.json create mode 100644 src/pages/console/comment/list/index.ts create mode 100644 src/pages/console/comment/list/locales/zh_CN.json create mode 100644 src/pages/console/comment/list/styles.module.less create mode 100644 src/pages/console/comment/list/web.pc.tsx create mode 100644 src/triggers/likes.ts diff --git a/src/checkers/essay.ts b/src/checkers/essay.ts index ee4126d..838aabb 100644 --- a/src/checkers/essay.ts +++ b/src/checkers/essay.ts @@ -88,6 +88,21 @@ const checkers: Checker[] = [ }, option ); + }, + () => { + // 删除相关的comment + return context.operate( + 'comment', + { + action: 'remove', + id: generateNewId(), + data: {}, + filter: { + essay: filter, + }, + }, + option + ); } ); }, diff --git a/src/components/console/likes/index.json b/src/components/console/likes/index.json new file mode 100644 index 0000000..aacb8c0 --- /dev/null +++ b/src/components/console/likes/index.json @@ -0,0 +1,5 @@ +{ + "enablePullDownRefresh": false, + "usingComponents": { + } +} \ No newline at end of file diff --git a/src/components/console/likes/index.ts b/src/components/console/likes/index.ts new file mode 100644 index 0000000..8dc8877 --- /dev/null +++ b/src/components/console/likes/index.ts @@ -0,0 +1,11 @@ +export default OakComponent({ + entity: 'likes', + isList: true, + projection: { + }, + formData({ data }) { + return { + list: data, + }; + }, +}); diff --git a/src/components/console/likes/locales/zh_CN.json b/src/components/console/likes/locales/zh_CN.json new file mode 100644 index 0000000..544b7b4 --- /dev/null +++ b/src/components/console/likes/locales/zh_CN.json @@ -0,0 +1,3 @@ +{ + +} \ No newline at end of file diff --git a/src/components/console/likes/styles.module.less b/src/components/console/likes/styles.module.less new file mode 100644 index 0000000..b139135 --- /dev/null +++ b/src/components/console/likes/styles.module.less @@ -0,0 +1,7 @@ +.id { + font-size: 18px; +} + +.item { + font-size: 18px; +} \ No newline at end of file diff --git a/src/components/console/likes/web.pc.tsx b/src/components/console/likes/web.pc.tsx new file mode 100644 index 0000000..9e566df --- /dev/null +++ b/src/components/console/likes/web.pc.tsx @@ -0,0 +1,31 @@ +import React from 'react'; +import { EntityDict } from '@project/oak-app-domain'; +import { RowWithActions, WebComponentProps } from 'oak-frontend-base'; +import Styles from './styles.module.less'; + +const Likes = ( + props: WebComponentProps< + EntityDict, + 'likes', + true, + { + list: RowWithActions[]; + } + > +) => { + const { list } = props.data; + + return ( + <> + {list && ( + <> + {list.map((item) => { + return
{item.id}
; + })} + + )} + + ); +}; + +export default Likes; \ No newline at end of file diff --git a/src/components/frontend/home/comment/index.json b/src/components/frontend/home/comment/index.json new file mode 100644 index 0000000..aacb8c0 --- /dev/null +++ b/src/components/frontend/home/comment/index.json @@ -0,0 +1,5 @@ +{ + "enablePullDownRefresh": false, + "usingComponents": { + } +} \ No newline at end of file diff --git a/src/components/frontend/home/comment/index.ts b/src/components/frontend/home/comment/index.ts new file mode 100644 index 0000000..9ade6c0 --- /dev/null +++ b/src/components/frontend/home/comment/index.ts @@ -0,0 +1,13 @@ +export default OakComponent({ + entity: 'comment', + isList: true, + projection: { + content: 1, + }, + formData({ data }) { + return { + list: data, + essayId: this.props.essayId + }; + }, +}); diff --git a/src/components/frontend/home/comment/locales/zh_CN.json b/src/components/frontend/home/comment/locales/zh_CN.json new file mode 100644 index 0000000..544b7b4 --- /dev/null +++ b/src/components/frontend/home/comment/locales/zh_CN.json @@ -0,0 +1,3 @@ +{ + +} \ No newline at end of file diff --git a/src/components/frontend/home/comment/styles.module.less b/src/components/frontend/home/comment/styles.module.less new file mode 100644 index 0000000..68ed536 --- /dev/null +++ b/src/components/frontend/home/comment/styles.module.less @@ -0,0 +1,36 @@ +.id { + font-size: 18px; +} + +.item { + font-size: 18px; + width: 80%; + margin-left: auto; + margin-right: auto; + margin-bottom: 30px; +} + +.TextArea { + font-size: 18px; + width: 80%; + margin-left: auto; + margin-right: auto; + + .btu{ + margin-top: 20px; + margin-left: 50%; + } +} + +.content{ + margin-top: 30px; + margin-bottom: 70px; + width: 80%; + margin-left: auto; + margin-right: auto; + font-size: 25px; + background-color: #ffffffd3; + border-radius: 20px; + padding: 10px; + height: auto; +} diff --git a/src/components/frontend/home/comment/web.pc.tsx b/src/components/frontend/home/comment/web.pc.tsx new file mode 100644 index 0000000..eee0cea --- /dev/null +++ b/src/components/frontend/home/comment/web.pc.tsx @@ -0,0 +1,102 @@ +import React, { useState } from 'react'; +import { EntityDict } from '@project/oak-app-domain'; +import { RowWithActions, WebComponentProps } from 'oak-frontend-base'; +import Styles from './styles.module.less'; +import { Input } from 'antd'; +import { Button } from 'antd'; +import { set } from 'lodash'; +import useFeatures from '@project/hooks/useFeatures'; + +const { TextArea } = Input; + + +const Comment = ( + props: WebComponentProps< + EntityDict, + 'comment', + true, + { + list: RowWithActions[]; + essayId: string; + } + > +) => { + const features = useFeatures(); + const { t, addItem, execute } = props.methods; + const { list } = props.data; + const [newCommentText, setNewCommentText] = React.useState(''); + const [likePeople, setLikePeople] = React.useState([]); + const handleSubmit = () => { + addItem({ + content: newCommentText, + creatorId: features.token.getUserId(), + essayId: props.data.essayId, + }); + execute(); + setNewCommentText(''); + }; + + const MyButton = () => { + const clickPeople = features.token.getUserId(); + + const handleClick = () => { + if (!clickPeople) { + return; + } + + setLikePeople((prevLikePeople) => { + if (prevLikePeople.includes(clickPeople)) { + return prevLikePeople.filter(person => person !== clickPeople); + } else { + return [...prevLikePeople, clickPeople]; + } + }); + }; + const count = likePeople.length; + + return ( + + ); + } + + return ( + <> +
+
+                    Saber
+                    Archer
+                    Rider
+                    Berserker
+                    Lancer 
+                    Caster
+                    Assassin
+                
+
+ {list && ( + <> + {list.map((item) => { + return
{item.content}
; + })} + {/* textarea */} +
+ + {/* button */} +
+ + +
+
+ + )} + + ); +}; + +export default Comment; \ No newline at end of file diff --git a/src/data/i18n.ts b/src/data/i18n.ts index c85141d..16c6800 100644 --- a/src/data/i18n.ts +++ b/src/data/i18n.ts @@ -14,6 +14,19 @@ const i18ns: I18n[] = [ "createCategory": "创建分类" } }, + { + id: "63f061bd7f1010b396cadb4bb784734f", + namespace: "new-demo-p-console-comment-list", + language: "zh-CN", + module: "new-demo", + position: "src/pages/console/comment/list", + data: { + "pageTitle": "评论管理", + "content": "", + "creator": "", + "essay": "" + } + }, { id: "4813a0a3acdfac90d3b3b3cfa37de82c", namespace: "new-demo-p-console-essay-list", @@ -222,6 +235,14 @@ const i18ns: I18n[] = [ "categories": "分类" } }, + { + id: "1900728959beaf0b8fd7ffd5bb758dbe", + namespace: "new-demo-c-frontend-home-comment", + language: "zh-CN", + module: "new-demo", + position: "src/components/frontend/home/comment", + data: {} + }, { id: "6fd812246bb915f692124fc05bb9ffd4", namespace: "new-demo-c-frontend-home-labels-byCategory", @@ -328,7 +349,8 @@ const i18ns: I18n[] = [ "userManage": "用户管理", "relationManage": "关系管理", "consoleHome": "控制台首页", - "labelManage": "标签管理" + "labelManage": "标签管理", + "commentManage": "评论管理" } }, { @@ -549,6 +571,21 @@ const i18ns: I18n[] = [ } } }, + { + id: "f70261a2fc23af2a9f459353e5ac1ea3", + namespace: "comment", + language: "zh-CN", + module: "", + position: "oak-app-domain/Comment", + data: { + "name": "评论", + "attr": { + "creator": "创建者", + "content": "内容", + "essay": "文章" + } + } + }, { id: "b06ea1d96db9f0a2d2f3ff3ad966c9c5", namespace: "domain", diff --git a/src/entities/Comment.ts b/src/entities/Comment.ts new file mode 100644 index 0000000..ed9a6b9 --- /dev/null +++ b/src/entities/Comment.ts @@ -0,0 +1,24 @@ +import { String, Text, Boolean } from 'oak-domain/lib/types/DataType'; +import { ActionDef, EntityDesc, EntityShape } from 'oak-domain/lib/types'; +import { Schema as User } from 'oak-general-business/lib/entities/User'; +import { Schema as Essay } from './Essay'; + +//Comment.ts +export interface Schema extends EntityShape { + creator: User; + content: String<1024>; + essay: Essay; +} + +export const entityDesc: EntityDesc = { + locales: { + zh_CN: { + name: '评论', + attr: { + creator: '创建者', + content: '内容', + essay: '文章', + }, + }, + }, +}; \ No newline at end of file diff --git a/src/entities/Essay.ts b/src/entities/Essay.ts index 3580c95..6a495a4 100644 --- a/src/entities/Essay.ts +++ b/src/entities/Essay.ts @@ -35,7 +35,13 @@ export const IActionDef: ActionDef = { // 用户行为操作 export type CommonAction = 'setTop' | 'cancelTop'; -type Action = IAction | CommonAction; +export type LikeAction = + | 'like' + | 'unlike'; + +export type Action = IAction | CommonAction | LikeAction; + + export const entityDesc: EntityDesc< Schema, @@ -65,6 +71,8 @@ export const entityDesc: EntityDesc< withdraw: '撤回', setTop: '置顶', cancelTop: '取消置顶', + like: '点赞', + unlike: '取消点赞', }, v: { iState: { diff --git a/src/entities/Likes.ts b/src/entities/Likes.ts new file mode 100644 index 0000000..1878a0a --- /dev/null +++ b/src/entities/Likes.ts @@ -0,0 +1,37 @@ +import { String, Text, Boolean } from 'oak-domain/lib/types/DataType'; +import { ActionDef, EntityDesc, EntityShape } from 'oak-domain/lib/types'; +import { Schema as User } from 'oak-general-business/lib/entities/User'; +import { Schema as Essay } from './Essay'; + +//Likes.ts +export interface Schema extends EntityShape { + creator: User; + essay: Essay; +} + +type LikeAction = + | 'like' + | 'unlike'; + +export type Action = LikeAction; + +export const entityDesc: EntityDesc = { + locales: { + zh_CN: { + name: '点赞', + attr: { + creator: '创建者', + essay: '文章', + }, + action: { + like: '点赞', + unlike: '取消点赞', + }, + }, + }, + style: { + icon: { + unlike: '', + }, + }, +}; \ No newline at end of file diff --git a/src/features/Console.ts b/src/features/Console.ts index d6e5a8b..668da72 100644 --- a/src/features/Console.ts +++ b/src/features/Console.ts @@ -55,7 +55,6 @@ const menus: IMenu[] = [ icon: 'share', url: '/relation/entityList', parent: 'System', - destEntity: 'userRelation', actions: ['select'], }, // category @@ -63,16 +62,16 @@ const menus: IMenu[] = [ name: 'categoryManage', icon: 'stealth', url: '/category/list', - order: 2, destEntity: 'userRelation', + order: 2, actions: ['select'], }, { name: 'essayManage', icon: 'barrage', url: '/essay/list', - order: 3, destEntity: 'userRelation', + order: 3, actions: ['select'], }, // 标签关联 @@ -80,10 +79,18 @@ const menus: IMenu[] = [ name: 'labelManage', icon: 'accessory', url: '/label/list', - order: 4, destEntity: 'userRelation', + order: 4, actions: ['select'], }, + // 评论管理 + { + name: 'commentManage', + icon: 'message', + url: '/comment/list', + destEntity: 'userRelation', + order: 5, + }, ]; export default class Console extends BaseConsole { diff --git a/src/locales/common/zh_CN.json b/src/locales/common/zh_CN.json index 2cc8159..35b1017 100644 --- a/src/locales/common/zh_CN.json +++ b/src/locales/common/zh_CN.json @@ -1,54 +1,55 @@ { - "name": "示例项目", - "unknown": "未知", - "status":"状态", - "ptrActivate": "松开刷新", - "ptrDeactivate": "下拉刷新", - "ptrRelease": "正在刷新...", - "ptrFinish": "刷新完成", - "noData": "暂无数据", - "areYouSure": "请确认", - "action": { - "create": "创建", - "update": "更新", - "delete": "删除", - "remove": "删除", - "cancel": "取消", - "grant": "授权", - "revoke": "回收", - "tip": "提示", - "detail": "详情", - "editor": "编辑", - "newAdd": "新增", - "add": "添加", - "commit": "提交", - "save": "保存", - "upload": "上传", - "import": "导入" - }, - "confirm": "确定", - "submit": "提交", - "reset": "重置", - "select": "查询", - "expand": "展开", - "shrink": "收起", - "back": "返回", - "$$createAt$$": "创建时间", - "$$updateAt$$": "更新时间", - "$$deleteAt$$": "删除时间", - "$$seq$$": "序号", - "message": "消息", - "more": "更多", - "view": "查看", - "scan": "扫一扫", - "bind": "绑定", - "true": "是", - "false": "否", - "open": "开", - "close": "关", - "enter": "请输入", - "change": "修改", - "finish": "完成", - "creator": "创建人", - "top": "置顶" -} + "name": "示例项目", + "unknown": "未知", + "status": "状态", + "ptrActivate": "松开刷新", + "ptrDeactivate": "下拉刷新", + "ptrRelease": "正在刷新...", + "ptrFinish": "刷新完成", + "noData": "暂无数据", + "areYouSure": "请确认", + "action": { + "create": "创建", + "update": "更新", + "delete": "删除", + "remove": "删除", + "cancel": "取消", + "grant": "授权", + "revoke": "回收", + "tip": "提示", + "detail": "详情", + "editor": "编辑", + "newAdd": "新增", + "add": "添加", + "commit": "提交", + "save": "保存", + "upload": "上传", + "import": "导入" + }, + "confirm": "确定", + "submit": "提交", + "reset": "重置", + "select": "查询", + "expand": "展开", + "shrink": "收起", + "back": "返回", + "$$createAt$$": "创建时间", + "$$updateAt$$": "更新时间", + "$$deleteAt$$": "删除时间", + "$$seq$$": "序号", + "message": "消息", + "more": "更多", + "view": "查看", + "scan": "扫一扫", + "bind": "绑定", + "true": "是", + "false": "否", + "open": "开", + "close": "关", + "enter": "请输入", + "change": "修改", + "finish": "完成", + "creator": "创建人", + "top": "置顶", + "like": "点赞" +} \ No newline at end of file diff --git a/src/locales/menu/zh_CN.json b/src/locales/menu/zh_CN.json index cd10c0b..63bbede 100644 --- a/src/locales/menu/zh_CN.json +++ b/src/locales/menu/zh_CN.json @@ -5,5 +5,6 @@ "userManage": "用户管理", "relationManage": "关系管理", "consoleHome" : "控制台首页", - "labelManage": "标签管理" + "labelManage": "标签管理", + "commentManage": "评论管理" } diff --git a/src/pages/console/comment/list/index.json b/src/pages/console/comment/list/index.json new file mode 100644 index 0000000..aacb8c0 --- /dev/null +++ b/src/pages/console/comment/list/index.json @@ -0,0 +1,5 @@ +{ + "enablePullDownRefresh": false, + "usingComponents": { + } +} \ No newline at end of file diff --git a/src/pages/console/comment/list/index.ts b/src/pages/console/comment/list/index.ts new file mode 100644 index 0000000..86273dd --- /dev/null +++ b/src/pages/console/comment/list/index.ts @@ -0,0 +1,20 @@ +export default OakComponent({ + entity: 'comment', + isList: true, + projection: { + content: 1, + essay: { + title: 1, + }, + creator: { + name: 1, + nickname: 1, + }, + }, + formData({ data }) { + return { + list: data, + }; + }, + actions: ['update', 'remove'], +}); diff --git a/src/pages/console/comment/list/locales/zh_CN.json b/src/pages/console/comment/list/locales/zh_CN.json new file mode 100644 index 0000000..60b0f0c --- /dev/null +++ b/src/pages/console/comment/list/locales/zh_CN.json @@ -0,0 +1,6 @@ +{ + "pageTitle": "评论管理", + "content": "", + "creator": "", + "essay": "" +} \ No newline at end of file diff --git a/src/pages/console/comment/list/styles.module.less b/src/pages/console/comment/list/styles.module.less new file mode 100644 index 0000000..b139135 --- /dev/null +++ b/src/pages/console/comment/list/styles.module.less @@ -0,0 +1,7 @@ +.id { + font-size: 18px; +} + +.item { + font-size: 18px; +} \ No newline at end of file diff --git a/src/pages/console/comment/list/web.pc.tsx b/src/pages/console/comment/list/web.pc.tsx new file mode 100644 index 0000000..8a09436 --- /dev/null +++ b/src/pages/console/comment/list/web.pc.tsx @@ -0,0 +1,74 @@ +import React from 'react'; +import { EntityDict } from '@project/oak-app-domain'; +import { RowWithActions, WebComponentProps } from 'oak-frontend-base'; +import Styles from './styles.module.less'; +import PageHeader from 'oak-frontend-base/es/components/pageHeader2'; +import { ListPro } from '@project/components/AbstractComponents'; +import { render } from 'nprogress'; +import { exec } from 'child_process'; + +const List = ( + props: WebComponentProps< + EntityDict, + 'comment', + true, + { + list: RowWithActions[]; + } + > +) => { + const { list } = props.data; + const{ t, removeItem, execute } = props.methods; + + const attrs = [ + { + path: 'content', + label: t('content'), + render: (row:any) => { + return row.content; + }, + }, + { + path: 'creator', + label: t('creator'), + render: (row:any) => { + return row.creator?.name || row.creator?.nickname || ''; + }, + }, + { + path: 'essay', + label: t('essay'), + render: (row:any) => { + return row.essay?.title || ''; + }, + }, + ]; + + const onAction = (row: any, action: string) => { + switch (action) { + case 'update': + break; + case 'remove': + removeItem(row.id); + execute(); + break; + default: + break; + } + }; + + return ( + + 我是米哈游的狗 + + + ); +}; + +export default List; \ No newline at end of file diff --git a/src/pages/frontend/essay/details/web.pc.tsx b/src/pages/frontend/essay/details/web.pc.tsx index e3078f6..349ff4f 100644 --- a/src/pages/frontend/essay/details/web.pc.tsx +++ b/src/pages/frontend/essay/details/web.pc.tsx @@ -6,6 +6,7 @@ import MdViewer from '@project/components/common/byteMD/MdViewer'; import FrontendFooter from '@project/components/frontend/home/FrontendFooter'; import { Button } from 'antd'; import { VerticalAlignTopOutlined } from '@ant-design/icons'; +import List from '@project/components/frontend/home/comment'; const EssayDetails = ( props: WebComponentProps< @@ -18,6 +19,8 @@ const EssayDetails = ( } > ) => { + const { oakFullpath } = props.data; + const { item, cover } = props.data; const [showScrollTop, setShowScrollTop] = useState(false); @@ -77,6 +80,10 @@ const EssayDetails = ( +
)} @@ -87,6 +94,7 @@ const EssayDetails = ( diff --git a/src/triggers/essay.ts b/src/triggers/essay.ts index 194010a..7c5cf6d 100644 --- a/src/triggers/essay.ts +++ b/src/triggers/essay.ts @@ -52,6 +52,61 @@ const triggers: Trigger[] = [ return 1; }, }, + + { + name: '点赞', + entity: 'essay', + action: 'create', // 假设我们有一个 action 名称 `createLike` 表示点赞 + when: 'after', + fn: async ({ operation }, context, option) => { + const { data } = operation; + assert(data && !Array.isArray(data)); + + // 获取当前用户 ID + const userId = context.getCurrentUserId(); + // 初始化 meta 和 likes 列表 + data.meta = data.meta || {}; + data.meta.likes = data.meta.likes || []; + + // 检查用户是否已点赞 + if (!data.meta.likes.includes(userId)) { + // 添加用户 ID 到 likes 列表 + data.meta.likes.push(userId); + // 增加点赞计数 + data.likesCount = (data.likesCount || 0) + 1; + } + + return 1; + }, + }, + + { + name: '取消点赞', + entity: 'essay', + action: 'create', // 假设我们有一个 action 名称 `removeLike` 表示取消点赞 + when: 'after', + fn: async ({ operation }, context, option) => { + const { data } = operation; + assert(data && !Array.isArray(data)); + + // 获取当前用户 ID + const userId = context.getCurrentUserId(); + // 初始化 meta 和 likes 列表 + data.meta = data.meta || {}; + data.meta.likes = data.meta.likes || []; + + // 检查用户是否已点赞 + const index = data.meta.likes.indexOf(userId); + if (index !== -1) { + // 从 likes 列表中移除用户 ID + data.meta.likes.splice(index, 1); + // 减少点赞计数 + data.likesCount = (data.likesCount || 0) - 1; + } + + return 1; + }, + } ]; export default triggers; diff --git a/src/triggers/index.ts b/src/triggers/index.ts index 30e4e00..3a6d049 100644 --- a/src/triggers/index.ts +++ b/src/triggers/index.ts @@ -4,11 +4,13 @@ import { BackendRuntimeContext } from '../context/BackendRuntimeContext'; import essayTriggers from './essay'; import essayLabelsTriggers from './essayLabels'; import labelTriggers from './label'; +import likesTriggers from './likes'; const triggers = [ ...essayTriggers, ...essayLabelsTriggers, ...labelTriggers, + ...likesTriggers, ] as Trigger[]; export default triggers; diff --git a/src/triggers/likes.ts b/src/triggers/likes.ts new file mode 100644 index 0000000..362ee8d --- /dev/null +++ b/src/triggers/likes.ts @@ -0,0 +1,35 @@ +import { EntityDict } from '@oak-app-domain'; +import { OakUserException, Trigger } from 'oak-domain/lib/types'; +import { BackendRuntimeContext } from '../context/BackendRuntimeContext'; +import assert from 'assert'; + +const triggers: Trigger[] = [ + { + name: '点赞', + entity: 'likes', + action: 'create', + when: 'after', + fn: async ({ operation }, context, option) => { + const { data } = operation; + assert(data && !Array.isArray(data)); + return 1; + }, + }, + + { + name: '取消点赞', + entity: 'likes', + action: 'remove', + when: 'after', + fn: async ({ operation }, context, option) => { + const { data } = operation; + assert(data && !Array.isArray(data)); + + const id = context.getCurrentUserId(); + + return 1; + }, + }, +]; + +export default triggers;