Feat/note on order (#399)

* added NoteService and related endpoints && tests

* removed snapshots

* corrected error in service

* removed snapshot

* added the ability to note down author using a string

* updated model for note

* refactored to access logged in user

* added other user id option

* removed snapshot

* updated according to feedback

* removed snapshots

* reintroduced snapshots

* updated to snake case

* removed try catch from use-db
This commit is contained in:
Sebastian Mateos Nicolajsen
2021-09-22 15:19:35 +02:00
committed by GitHub
parent a82332da3e
commit 897ccf475a
18 changed files with 1054 additions and 46 deletions
+96
View File
@@ -0,0 +1,96 @@
import {
Entity,
BeforeInsert,
Column,
DeleteDateColumn,
CreateDateColumn,
UpdateDateColumn,
Index,
JoinColumn,
PrimaryColumn,
ManyToOne,
} from "typeorm"
import { ulid } from "ulid"
import { User } from "./user"
import { resolveDbType, DbAwareColumn } from "../utils/db-aware-column"
@Entity()
export class Note {
@PrimaryColumn()
id: string
@Column()
value: string
@Index()
@Column()
resource_type: string
@Index()
@Column()
resource_id: string
@Column({ nullable: true })
author_id: string
@ManyToOne(() => User)
@JoinColumn({ name: "author_id" })
author: User
@CreateDateColumn({ type: resolveDbType("timestamptz") })
created_at: Date
@UpdateDateColumn({ type: resolveDbType("timestamptz") })
updated_at: Date
@DeleteDateColumn({ type: resolveDbType("timestamptz") })
deleted_at: Date
@DbAwareColumn({ type: "jsonb", nullable: true })
metadata: any
@BeforeInsert()
private beforeInsert() {
if (this.id) return
const id = ulid()
this.id = `note_${id}`
}
}
/**
* @schema note
* title: "Note"
* description: "Notes are elements which we can use in association with different resources to allow users to describe additional information in relation to these."
* x-resourceId: note
* properties:
* id:
* description: "The id of the Note. This value will be prefixed by `note_`."
* type: string
* resource_type:
* description: "The type of resource that the Note refers to."
* type: string
* resource_id:
* description: "The id of the resource that the Note refers to."
* type: string
* value:
* description: "The contents of the note."
* type: string
* author:
* description: "The author of the note."
* type: User
* created_at:
* description: "The date with timezone at which the resource was created."
* type: string
* format: date-time
* updated_at:
* description: "The date with timezone at which the resource was last updated."
* type: string
* format: date-time
* deleted_at:
* description: "The date with timezone at which the resource was deleted."
* type: string
* format: date-time
* metadata:
* description: "An optional key-value map with additional information."
* type: object
*/