From 4a0138297e60c36f6d72b510c0ebfa7211260b41 Mon Sep 17 00:00:00 2001 From: mattyatea Date: Thu, 16 May 2024 01:50:40 +0900 Subject: [PATCH] update --- package.json | 2 +- .../backend/migration/1715787239605-loginbonus.js | 6 ++++-- .../backend/migration/1715791271605-loginbonus1.js | 13 +++++++++++++ .../backend/src/core/entities/UserEntityService.ts | 3 +-- packages/backend/src/models/User.ts | 5 +++++ packages/backend/src/models/UserProfile.ts | 4 ---- packages/backend/src/server/api/endpoints/i.ts | 7 +++++-- 7 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 packages/backend/migration/1715791271605-loginbonus1.js diff --git a/package.json b/package.json index 6310884de8..6165b68e55 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "misskey", - "version": "2024.5.0-beta1-mattyatea1", + "version": "2024.5.0-beta1-mattyatea2", "codename": "nasubi", "repository": { "type": "git", diff --git a/packages/backend/migration/1715787239605-loginbonus.js b/packages/backend/migration/1715787239605-loginbonus.js index ce7410277f..b12fa3c76c 100644 --- a/packages/backend/migration/1715787239605-loginbonus.js +++ b/packages/backend/migration/1715787239605-loginbonus.js @@ -1,9 +1,11 @@ +import {Column} from "typeorm"; + export class Loginbonus1715787239605 { name = 'Loginbonus1715787239605' async up(queryRunner) { - await queryRunner.query(`ALTER TABLE "user_profile" ADD "getPoints" integer NOT NULL DEFAULT '0'`); } + await queryRunner.query(`ALTER TABLE "user_profile" DROP COLUMN "getPoints"`); } async down(queryRunner) { - await queryRunner.query(`ALTER TABLE "user_profile" DROP COLUMN "getPoints"`); } + await queryRunner.query(`ALTER TABLE "user_profile" ADD "getPoints" integer NOT NULL DEFAULT '0'`); } } diff --git a/packages/backend/migration/1715791271605-loginbonus1.js b/packages/backend/migration/1715791271605-loginbonus1.js new file mode 100644 index 0000000000..7dc8e1e709 --- /dev/null +++ b/packages/backend/migration/1715791271605-loginbonus1.js @@ -0,0 +1,13 @@ +export class Loginbonus11715791271605 { + name = 'Loginbonus11715791271605' + + async up(queryRunner) { + await queryRunner.query(`ALTER TABLE "user_profile" DROP COLUMN "getPoints"`); + await queryRunner.query(`ALTER TABLE "user" ADD "getPoints" integer NOT NULL DEFAULT '0'`); + } + + async down(queryRunner) { + await queryRunner.query(`ALTER TABLE "user" DROP COLUMN "getPoints"`); + await queryRunner.query(`ALTER TABLE "user_profile" ADD "getPoints" integer NOT NULL DEFAULT '0'`); + } +} diff --git a/packages/backend/src/core/entities/UserEntityService.ts b/packages/backend/src/core/entities/UserEntityService.ts index 3cdd66b53b..b8c8253126 100644 --- a/packages/backend/src/core/entities/UserEntityService.ts +++ b/packages/backend/src/core/entities/UserEntityService.ts @@ -471,9 +471,8 @@ export class UserEntityService implements OnModuleInit { createdAt: this.idService.parse(announcement.id).date.toISOString(), ...announcement, })) : null; - + console.log(user.getPoints); const notificationsInfo = isMe && isDetailed ? await this.getNotificationsInfo(user.id) : null; - const packed = { id: user.id, name: user.name, diff --git a/packages/backend/src/models/User.ts b/packages/backend/src/models/User.ts index 837e6bc966..7bfba85b95 100644 --- a/packages/backend/src/models/User.ts +++ b/packages/backend/src/models/User.ts @@ -25,6 +25,11 @@ export class MiUser { }) public lastFetchedAt: Date | null; + @Column('integer', { + default: '0', + }) + public getPoints: number; + @Index() @Column('timestamp with time zone', { nullable: true, diff --git a/packages/backend/src/models/UserProfile.ts b/packages/backend/src/models/UserProfile.ts index ef70a297a9..7dbe0b3717 100644 --- a/packages/backend/src/models/UserProfile.ts +++ b/packages/backend/src/models/UserProfile.ts @@ -261,10 +261,6 @@ export class MiUserProfile { length: 32, array: true, default: '{}', }) public loggedInDates: string[]; - @Column('integer', { - default: '0', - }) - public getPoints: number; @Column('jsonb', { default: [], diff --git a/packages/backend/src/server/api/endpoints/i.ts b/packages/backend/src/server/api/endpoints/i.ts index 08bf8b70c2..475468dac3 100644 --- a/packages/backend/src/server/api/endpoints/i.ts +++ b/packages/backend/src/server/api/endpoints/i.ts @@ -4,7 +4,7 @@ */ import { Inject, Injectable } from '@nestjs/common'; -import type { UserProfilesRepository } from '@/models/_.js'; +import type { UserProfilesRepository, UsersRepository } from '@/models/_.js'; import { Endpoint } from '@/server/api/endpoint-base.js'; import { UserEntityService } from '@/core/entities/UserEntityService.js'; import { DI } from '@/di-symbols.js'; @@ -44,6 +44,9 @@ export default class extends Endpoint { // eslint- constructor( @Inject(DI.userProfilesRepository) private userProfilesRepository: UserProfilesRepository, + @Inject(DI.usersRepository) + private usersRepository: UsersRepository, + private notificationService: NotificationService, private userEntityService: UserEntityService, ) { @@ -70,7 +73,7 @@ export default class extends Endpoint { // eslint- this.userProfilesRepository.update({ userId: user.id }, { loggedInDates: [...userProfile.loggedInDates, today], }); - this.userProfilesRepository.update({ userId: user.id }, { + this.usersRepository.update({ userId: user.id }, { getPoints: userProfile.getPoints + todayGetPoints, }); this.notificationService.createNotification(user.id, 'loginbonus', {