mirror of
https://github.com/usatiuk/writer.git
synced 2025-10-29 00:17:48 +01:00
save document's edit time
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -73,6 +73,7 @@ docsRouter.patch("/docs/byID/:id", async ctx => {
|
||||
}
|
||||
|
||||
try {
|
||||
document.editedAt = new Date();
|
||||
await document.save();
|
||||
} catch (e) {
|
||||
ctx.throw(400);
|
||||
|
||||
@@ -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 () => {
|
||||
|
||||
Reference in New Issue
Block a user