feat: 增加 inbox.append 接口,用于内部调用增加收件箱内容

pull/70/head
moonrailgun 2 years ago
parent f77d267f80
commit 56c9f99c67

@ -4,6 +4,8 @@ import {
DocumentType,
Ref,
index,
modelOptions,
Severity,
} from '@typegoose/typegoose';
import { Base, TimeStamps } from '@typegoose/typegoose/lib/defaultClasses';
import type { Types } from 'mongoose';
@ -38,6 +40,11 @@ class InboxMessage {
/**
*
*/
@modelOptions({
options: {
allowMixed: Severity.ALLOW,
},
})
@index({ userId: 1 })
export class Inbox extends TimeStamps implements Base {
_id: Types.ObjectId;
@ -60,6 +67,12 @@ export class Inbox extends TimeStamps implements Base {
})
message?: InboxMessage;
/**
*
*/
@prop()
payload?: object;
/**
*
*/

@ -56,6 +56,14 @@ class InboxService extends TcService {
}
);
this.registerAction('append', this.append, {
visibility: 'public',
params: {
userId: { type: 'string', optional: true },
type: 'string',
payload: 'any',
},
});
this.registerAction('appendMessage', this.appendMessage, {
visibility: 'public',
params: {
@ -84,6 +92,35 @@ class InboxService extends TcService {
this.registerAction('clear', this.clear);
}
/**
* inbox
*
*/
async append(
ctx: TcContext<{
userId?: string;
type: string;
payload: any;
}>
) {
const { userId = ctx.meta.userId, type, payload } = ctx.params;
const doc = await this.adapter.model.create({
userId,
type,
payload,
});
const inboxItem = await this.transformDocuments(ctx, {}, doc);
await this.notifyUsersInboxAppend(ctx, [userId], inboxItem);
return true;
}
/**
*
*/
async appendMessage(
ctx: TcContext<{
userId?: string;

Loading…
Cancel
Save