2024-12-30 08:26:40 +08:00
|
|
|
import { Controller, Get, Query, UseGuards } from '@nestjs/common';
|
|
|
|
|
|
|
|
import { MessageService } from './message.service';
|
|
|
|
import { AuthGuard } from '@server/auth/auth.guard';
|
2025-01-06 08:45:23 +08:00
|
|
|
import { db, VisitType } from '@nice/common';
|
2024-12-30 08:26:40 +08:00
|
|
|
|
|
|
|
@Controller('message')
|
|
|
|
export class MessageController {
|
|
|
|
constructor(private readonly messageService: MessageService) { }
|
|
|
|
@UseGuards(AuthGuard)
|
|
|
|
@Get('find-last-one')
|
|
|
|
async findLastOne(@Query('staff-id') staffId: string) {
|
|
|
|
try {
|
|
|
|
const result = await db.message.findFirst({
|
|
|
|
where: {
|
|
|
|
OR: [
|
|
|
|
{
|
|
|
|
receivers: {
|
|
|
|
some: {
|
|
|
|
id: staffId,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
orderBy: { createdAt: 'desc' },
|
|
|
|
select: {
|
|
|
|
title: true,
|
|
|
|
content: true,
|
|
|
|
url: true
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
data: result,
|
|
|
|
errmsg: 'success',
|
|
|
|
errno: 0,
|
|
|
|
};
|
|
|
|
} catch (e) {
|
|
|
|
return {
|
|
|
|
data: {},
|
|
|
|
errmsg: (e as any)?.message || 'error',
|
|
|
|
errno: 1,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@UseGuards(AuthGuard)
|
|
|
|
@Get('find-unreaded')
|
|
|
|
async findUnreaded(@Query('staff-id') staffId: string) {
|
|
|
|
try {
|
|
|
|
const result = await db.message.findMany({
|
|
|
|
where: {
|
|
|
|
visits: {
|
|
|
|
none: {
|
|
|
|
id: staffId,
|
2024-12-31 15:57:32 +08:00
|
|
|
type: VisitType.READED
|
2024-12-30 08:26:40 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
receivers: {
|
|
|
|
some: {
|
|
|
|
id: staffId,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
orderBy: { createdAt: 'desc' },
|
|
|
|
select: {
|
|
|
|
title: true,
|
|
|
|
content: true,
|
|
|
|
url: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
data: result,
|
|
|
|
errmsg: 'success',
|
|
|
|
errno: 0,
|
|
|
|
};
|
|
|
|
} catch (e) {
|
|
|
|
return {
|
|
|
|
data: {},
|
|
|
|
errmsg: (e as any)?.message || 'error',
|
|
|
|
errno: 1,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@UseGuards(AuthGuard)
|
|
|
|
@Get('count-unreaded')
|
|
|
|
async countUnreaded(@Query('staff-id') staffId: string) {
|
|
|
|
try {
|
|
|
|
const result = await db.message.findMany({
|
|
|
|
where: {
|
|
|
|
visits: {
|
|
|
|
none: {
|
|
|
|
id: staffId,
|
2024-12-31 15:57:32 +08:00
|
|
|
type: VisitType.READED
|
2024-12-30 08:26:40 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
receivers: {
|
|
|
|
some: {
|
|
|
|
id: staffId,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
orderBy: { createdAt: 'desc' },
|
|
|
|
select: {
|
|
|
|
title: true,
|
|
|
|
content: true,
|
|
|
|
url: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
data: result,
|
|
|
|
errmsg: 'success',
|
|
|
|
errno: 0,
|
|
|
|
};
|
|
|
|
} catch (e) {
|
|
|
|
return {
|
|
|
|
data: {},
|
|
|
|
errmsg: (e as any)?.message || 'error',
|
|
|
|
errno: 1,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|