FoundKey/packages/backend/src/models/entities/poll.ts
Johann150 78359daac6
Some checks failed
ci/woodpecker/push/lint-foundkey-js Pipeline was successful
ci/woodpecker/push/lint-sw Pipeline failed
ci/woodpecker/push/lint-client Pipeline failed
ci/woodpecker/push/lint-backend Pipeline failed
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/test Pipeline failed
server: remove denormalized note visibility field
Changelog: Fixed
2024-01-03 16:13:13 +01:00

67 lines
1.2 KiB
TypeScript

import { PrimaryColumn, Entity, Index, JoinColumn, Column, OneToOne } from 'typeorm';
import { noteVisibilities } from 'foundkey-js';
import { id } from '../id.js';
import { Note } from './note.js';
import { User } from './user.js';
@Entity()
export class Poll {
@PrimaryColumn(id())
public noteId: Note['id'];
@OneToOne(() => Note, {
onDelete: 'CASCADE',
})
@JoinColumn()
public note: Note | null;
@Column('timestamp with time zone', {
nullable: true,
})
public expiresAt: Date | null;
@Column('boolean')
public multiple: boolean;
@Column('varchar', {
length: 128, array: true, default: '{}',
})
public choices: string[];
@Column('integer', {
array: true,
})
public votes: number[];
//#region Denormalized fields
@Index()
@Column({
...id(),
comment: '[Denormalized]',
})
public userId: User['id'];
@Index()
@Column('varchar', {
length: 128, nullable: true,
comment: '[Denormalized]',
})
public userHost: string | null;
//#endregion
constructor(data: Partial<Poll>) {
if (data == null) return;
for (const [k, v] of Object.entries(data)) {
(this as any)[k] = v;
}
}
}
export type IPoll = {
choices: string[];
votes?: number[];
multiple: boolean;
expiresAt: Date | null;
};