All files / owid-grapher/db/model User.ts

96.84% Statements 92/95
100% Branches 0/0
0% Functions 0/1
96.84% Lines 92/95

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 431x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x       1x 1x
import {
    Entity,
    PrimaryGeneratedColumn,
    Column,
    BaseEntity,
    OneToMany,
} from "typeorm"
import { Chart } from "./Chart"
import { Dataset } from "./Dataset"
import { ChartRevision } from "./ChartRevision"
import { BCryptHasher } from "../hashers"
 
@Entity("users")
export class User extends BaseEntity {
    @PrimaryGeneratedColumn() id!: number
    @Column({ unique: true }) email!: string
    @Column({ length: 128 }) password!: string
    @Column({ default: "" }) fullName!: string
    @Column({ default: true }) isActive!: boolean
    @Column({ default: false }) isSuperuser!: boolean
    @Column() createdAt!: Date
    @Column() updatedAt!: Date
    @Column() lastLogin!: Date
    @Column() lastSeen!: Date
 
    @OneToMany(() => Chart, (chart) => chart.lastEditedByUser)
    lastEditedCharts!: Chart[]
 
    @OneToMany(() => Chart, (chart) => chart.publishedByUser)
    publishedCharts!: Chart[]
 
    @OneToMany(() => ChartRevision, (rev) => rev.user)
    editedCharts!: ChartRevision[]
 
    @OneToMany(() => Dataset, (dataset) => dataset.createdByUser)
    createdDatasets!: Dataset[]
 
    async setPassword(password: string): Promise<void> {
        const h = new BCryptHasher()
        this.password = await h.encode(password)
    }
}