save document's edit time

This commit is contained in:
2019-01-20 22:36:17 +03:00
parent 3b2d49a0d4
commit c072c7f7fc
3 changed files with 14 additions and 0 deletions

View File

@@ -8,6 +8,11 @@ import {
import { User } from "./User";
export type IDocumentJSON = Pick<
Document,
"id" | "user" | "name" | "content" | "createdAt"
>;
@Entity()
export class Document extends BaseEntity {
@PrimaryGeneratedColumn()
@@ -25,9 +30,13 @@ export class Document extends BaseEntity {
@Column({ type: "timestamp" })
public createdAt: Date;
@Column({ type: "timestamp" })
public editedAt: Date;
constructor(user: User, name: string, content: string) {
super();
this.createdAt = new Date();
this.editedAt = this.createdAt;
this.user = user;
this.name = name;
this.content = content;

View File

@@ -73,6 +73,7 @@ docsRouter.patch("/docs/byID/:id", async ctx => {
}
try {
document.editedAt = new Date();
await document.save();
} catch (e) {
ctx.throw(400);

View File

@@ -71,6 +71,10 @@ describe("docs", () => {
});
expect(dbDocument.name).to.be.equal("Test1");
expect(dbDocument.editedAt.getTime()).to.be.closeTo(
new Date().getTime(),
1000,
);
});
it("should list docs", async () => {