Improve typing

This commit is contained in:
tamaina
2020-05-26 14:33:55 +09:00
parent 05c7cacdd1
commit 9bee9d20f7
9 changed files with 24 additions and 10 deletions

View File

@ -2,6 +2,8 @@ import { Entity, Index, JoinColumn, Column, PrimaryColumn, ManyToOne } from 'typ
import { User } from './user';
import { DriveFile } from './drive-file';
import { id } from '../id';
import { noteVisibilities } from '../../types';
@Entity()
@Index('IDX_NOTE_TAGS', { synchronize: false })
@ -102,8 +104,8 @@ export class Note {
* followers ... フォロワーのみ
* specified ... visibleUserIds で指定したユーザーのみ
*/
@Column('enum', { enum: ['public', 'home', 'followers', 'specified'] })
public visibility: 'public' | 'home' | 'followers' | 'specified';
@Column('enum', { enum: noteVisibilities })
public visibility: typeof noteVisibilities[number];
@Index({ unique: true })
@Column('varchar', {

View File

@ -5,6 +5,7 @@ import { Note } from './note';
import { FollowRequest } from './follow-request';
import { UserGroupInvitation } from './user-group-invitation';
import { AccessToken } from './access-token';
import { notificationTypes } from '../../types';
@Entity()
export class Notification {
@ -66,10 +67,10 @@ export class Notification {
*/
@Index()
@Column('enum', {
enum: ['follow', 'mention', 'reply', 'renote', 'quote', 'reaction', 'pollVote', 'receiveFollowRequest', 'followRequestAccepted', 'groupInvited', 'app'],
enum: notificationTypes,
comment: 'The type of the Notification.'
})
public type: 'follow' | 'mention' | 'reply' | 'renote' | 'quote' | 'reaction' | 'pollVote' | 'receiveFollowRequest' | 'followRequestAccepted' | 'groupInvited' | 'app';
public type: typeof notificationTypes[number];
/**
* 通知が読まれたかどうか

View File

@ -2,6 +2,7 @@ import { PrimaryColumn, Entity, Index, JoinColumn, Column, OneToOne } from 'type
import { id } from '../id';
import { Note } from './note';
import { User } from './user';
import { noteVisibilities } from '../../types';
@Entity()
export class Poll {
@ -34,10 +35,10 @@ export class Poll {
//#region Denormalized fields
@Column('enum', {
enum: ['public', 'home', 'followers', 'specified'],
enum: noteVisibilities,
comment: '[Denormalized]'
})
public noteVisibility: 'public' | 'home' | 'followers' | 'specified';
public noteVisibility: typeof noteVisibilities[number];
@Index()
@Column({

View File

@ -19,6 +19,7 @@ export class NotificationRepository extends Repository<Notification> {
id: notification.id,
createdAt: notification.createdAt.toISOString(),
type: notification.type,
isRead: notification.isRead,
userId: notification.notifierId,
user: notification.notifierId ? Users.pack(notification.notifier || notification.notifierId) : null,
...(notification.type === 'mention' ? {