mirror of
https://github.com/n8n-io/n8n.git
synced 2024-09-27 18:27:36 -07:00
027dfb2f0a
* ⚡ Enable `esModuleInterop` for /core * ⚡ Adjust imports in /core * ⚡ Enable `esModuleInterop` for /cli * ⚡ Adjust imports in /cli * ⚡ Enable `esModuleInterop` for /nodes-base * ⚡ Adjust imports in /nodes-base * ⚡ Make imports consistent * ⬆️ Upgrade TypeScript to 4.6 (#3109) * ⬆️ Upgrade TypeScript to 4.6 * 📦 Update package-lock.json * 🔧 Avoid erroring on untyped errors * 📘 Fix type error Co-authored-by: Jan Oberhauser <jan.oberhauser@gmail.com>
71 lines
1.8 KiB
TypeScript
71 lines
1.8 KiB
TypeScript
/* eslint-disable import/no-cycle */
|
|
import {
|
|
BeforeUpdate,
|
|
CreateDateColumn,
|
|
Entity,
|
|
ManyToOne,
|
|
RelationId,
|
|
UpdateDateColumn,
|
|
} from 'typeorm';
|
|
import { IsDate, IsOptional } from 'class-validator';
|
|
|
|
import * as config from '../../../config';
|
|
import { DatabaseType } from '../../index';
|
|
import { WorkflowEntity } from './WorkflowEntity';
|
|
import { User } from './User';
|
|
import { Role } from './Role';
|
|
|
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
|
|
function getTimestampSyntax() {
|
|
const dbType = config.getEnv('database.type');
|
|
|
|
const map: { [key in DatabaseType]: string } = {
|
|
sqlite: "STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')",
|
|
postgresdb: 'CURRENT_TIMESTAMP(3)',
|
|
mysqldb: 'CURRENT_TIMESTAMP(3)',
|
|
mariadb: 'CURRENT_TIMESTAMP(3)',
|
|
};
|
|
|
|
return map[dbType];
|
|
}
|
|
|
|
@Entity()
|
|
export class SharedWorkflow {
|
|
@ManyToOne(() => Role, (role) => role.sharedWorkflows, { nullable: false })
|
|
role: Role;
|
|
|
|
@ManyToOne(() => User, (user) => user.sharedWorkflows, { primary: true })
|
|
user: User;
|
|
|
|
@RelationId((sharedWorkflow: SharedWorkflow) => sharedWorkflow.user)
|
|
userId: string;
|
|
|
|
@ManyToOne(() => WorkflowEntity, (workflow) => workflow.shared, {
|
|
primary: true,
|
|
onDelete: 'CASCADE',
|
|
})
|
|
workflow: WorkflowEntity;
|
|
|
|
@RelationId((sharedWorkflow: SharedWorkflow) => sharedWorkflow.workflow)
|
|
workflowId: number;
|
|
|
|
@CreateDateColumn({ precision: 3, default: () => getTimestampSyntax() })
|
|
@IsOptional() // ignored by validation because set at DB level
|
|
@IsDate()
|
|
createdAt: Date;
|
|
|
|
@UpdateDateColumn({
|
|
precision: 3,
|
|
default: () => getTimestampSyntax(),
|
|
onUpdate: getTimestampSyntax(),
|
|
})
|
|
@IsOptional() // ignored by validation because set at DB level
|
|
@IsDate()
|
|
updatedAt: Date;
|
|
|
|
@BeforeUpdate()
|
|
setUpdateDate(): void {
|
|
this.updatedAt = new Date();
|
|
}
|
|
}
|