refactor: introduce bindThis decorator to bind this automaticaly

This commit is contained in:
syuilo
2022-12-04 15:03:09 +09:00
parent e73581f715
commit bbb49457f9
199 changed files with 969 additions and 96 deletions

View File

@ -8,6 +8,7 @@ import { UserSuspendService } from '@/core/UserSuspendService.js';
import { UserFollowingService } from '@/core/UserFollowingService.js';
import { DI } from '@/di-symbols.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { bindThis } from '@/decorators.js';
export const meta = {
tags: ['admin'],
@ -79,6 +80,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
});
}
@bindThis
private async unFollowAll(follower: User) {
const followings = await this.followingsRepository.findBy({
followerId: follower.id,
@ -97,6 +99,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
}
}
@bindThis
private async readAllNotify(notifier: User) {
await this.notificationsRepository.update({
notifierId: notifier.id,

View File

@ -15,6 +15,7 @@ import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { UtilityService } from '@/core/UtilityService.js';
import { DI } from '@/di-symbols.js';
import { bindThis } from '@/decorators.js';
import { ApiError } from '../../error.js';
export const meta = {
@ -112,6 +113,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
/***
* URIからUserかNoteを解決する
*/
@bindThis
private async fetchAny(uri: string, me: CacheableLocalUser | null | undefined): Promise<SchemaType<typeof meta['res']> | null> {
// ブロックしてたら中断
const fetchedMeta = await this.metaService.fetch();
@ -144,6 +146,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
);
}
@bindThis
private async mergePack(me: CacheableLocalUser | null | undefined, user: User | null | undefined, note: Note | null | undefined): Promise<SchemaType<typeof meta.res> | null> {
if (user != null) {
return {