update
This commit is contained in:
parent
5e140a7ff5
commit
509181a6d0
9 changed files with 288 additions and 229 deletions
|
|
@ -163,6 +163,9 @@ export class NotificationEntityService implements OnModuleInit {
|
|||
...(notification.type === 'achievementEarned' ? {
|
||||
achievement: notification.achievement,
|
||||
} : {}),
|
||||
...(notification.type === 'loginbonus' ? {
|
||||
loginbonus: notification.loginbonus,
|
||||
} : {}),
|
||||
...(notification.type === 'app' ? {
|
||||
body: notification.customBody,
|
||||
header: notification.customHeader,
|
||||
|
|
|
|||
|
|
@ -404,6 +404,7 @@ export class UserEntityService implements OnModuleInit {
|
|||
userRelations?: Map<MiUser['id'], UserRelation>,
|
||||
userMemos?: Map<MiUser['id'], string | null>,
|
||||
pinNotes?: Map<MiUser['id'], MiUserNotePining[]>,
|
||||
todayGetPoints?: number,
|
||||
},
|
||||
): Promise<Packed<S>> {
|
||||
const opts = Object.assign({
|
||||
|
|
@ -507,7 +508,7 @@ export class UserEntityService implements OnModuleInit {
|
|||
iconUrl: r.iconUrl,
|
||||
displayOrder: r.displayOrder,
|
||||
}))) : undefined,
|
||||
|
||||
...(user.host == null ? { getPoints: profile!.getPoints } : {}),
|
||||
...(isDetailed ? {
|
||||
url: profile!.url,
|
||||
uri: user.uri,
|
||||
|
|
@ -602,6 +603,9 @@ export class UserEntityService implements OnModuleInit {
|
|||
achievements: profile!.achievements,
|
||||
loggedInDays: profile!.loggedInDates.length,
|
||||
policies: this.roleService.getUserPolicies(user.id),
|
||||
...(opts.todayGetPoints ? {
|
||||
todayGetPoints: opts.todayGetPoints,
|
||||
} : {}),
|
||||
} : {}),
|
||||
|
||||
...(opts.includeSecrets ? {
|
||||
|
|
|
|||
|
|
@ -261,6 +261,10 @@ export class MiUserProfile {
|
|||
length: 32, array: true, default: '{}',
|
||||
})
|
||||
public loggedInDates: string[];
|
||||
@Column('integer', {
|
||||
default: '0',
|
||||
})
|
||||
public getPoints: number;
|
||||
|
||||
@Column('jsonb', {
|
||||
default: [],
|
||||
|
|
|
|||
|
|
@ -8,13 +8,14 @@ import type { UserProfilesRepository } from '@/models/_.js';
|
|||
import { Endpoint } from '@/server/api/endpoint-base.js';
|
||||
import { UserEntityService } from '@/core/entities/UserEntityService.js';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import { NotificationService } from '@/core/NotificationService.js';
|
||||
import { ApiError } from '../error.js';
|
||||
|
||||
export const meta = {
|
||||
tags: ['account'],
|
||||
|
||||
requireCredential: true,
|
||||
kind: "read:account",
|
||||
kind: 'read:account',
|
||||
|
||||
res: {
|
||||
type: 'object',
|
||||
|
|
@ -43,7 +44,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
constructor(
|
||||
@Inject(DI.userProfilesRepository)
|
||||
private userProfilesRepository: UserProfilesRepository,
|
||||
|
||||
private notificationService: NotificationService,
|
||||
private userEntityService: UserEntityService,
|
||||
) {
|
||||
super(meta, paramDef, async (ps, user, token) => {
|
||||
|
|
@ -51,7 +52,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
|
||||
const now = new Date();
|
||||
const today = `${now.getFullYear()}/${now.getMonth() + 1}/${now.getDate()}`;
|
||||
|
||||
let todayGetPoints = 0;
|
||||
// 渡ってきている user はキャッシュされていて古い可能性があるので改めて取得
|
||||
const userProfile = await this.userProfilesRepository.findOne({
|
||||
where: {
|
||||
|
|
@ -65,9 +66,16 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
}
|
||||
|
||||
if (!userProfile.loggedInDates.includes(today)) {
|
||||
todayGetPoints = Math.floor(Math.random() * 5) + 1;
|
||||
this.userProfilesRepository.update({ userId: user.id }, {
|
||||
loggedInDates: [...userProfile.loggedInDates, today],
|
||||
});
|
||||
this.userProfilesRepository.update({ userId: user.id }, {
|
||||
getPoints: userProfile.getPoints + todayGetPoints,
|
||||
});
|
||||
this.notificationService.createNotification(user.id, 'loginbonus', {
|
||||
loginbonus: todayGetPoints,
|
||||
});
|
||||
userProfile.loggedInDates = [...userProfile.loggedInDates, today];
|
||||
}
|
||||
|
||||
|
|
@ -75,6 +83,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
|
|||
schema: 'MeDetailed',
|
||||
includeSecrets: isSecure,
|
||||
userProfile,
|
||||
...(todayGetPoints && { todayGetPoints }),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ export const notificationTypes = [
|
|||
'achievementEarned',
|
||||
'app',
|
||||
'test',
|
||||
'loginbonus',
|
||||
] as const;
|
||||
|
||||
export const groupedNotificationTypes = [
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue