1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
| import { CoolController, BaseController } from '@cool-midway/core';
| import { CsMsgEntity } from '../../entity/msg';
| import { CsSessionEntity } from '../../entity/session';
| import { BaseSysUserEntity } from '../../../base/entity/sys/user';
| import { UserInfoEntity } from '../../../user/entity/info';
| import { Body, Get, Inject, Post } from '@midwayjs/core';
| import { CsMsgService } from '../../service/msg';
|
| /**
| * 消息
| */
| @CoolController({
| api: ['page'],
| entity: CsMsgEntity,
| pageQueryOp: {
| select: [
| 'a.*',
| 'b.nickName',
| 'b.avatarUrl',
| 'c.name as adminUserName',
| 'c.headImg as adminUserHeadImg',
| ],
| join: [
| {
| entity: UserInfoEntity,
| alias: 'b',
| condition: 'a.userId = b.id and a.type = 0',
| },
| {
| entity: BaseSysUserEntity,
| alias: 'c',
| condition: 'a.userId = c.id and a.type = 1',
| },
| {
| entity: CsSessionEntity,
| alias: 'd',
| condition: 'a.sessionId = d.id',
| },
| ],
| where: ctx => {
| return [['d.userId = :userId', { userId: ctx.user?.id }]];
| },
| },
| })
| export class AppCsMsgController extends BaseController {
| @Inject()
| ctx;
|
| @Inject()
| csMsgService: CsMsgService;
|
| @Get('/unreadCount', { summary: '未读消息数' })
| async unreadCount() {
| return this.ok(await this.csMsgService.unreadCount(this.ctx.user?.id, 1));
| }
|
| @Post('/read', { summary: '标记已读' })
| async read(@Body('msgIds') msgIds: number[]) {
| this.csMsgService.read(msgIds);
| return this.ok();
| }
| }
|
|