/
service.ts
44 lines (36 loc) · 836 Bytes
/
service.ts
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
43
44
// deno-lint-ignore-file camelcase
import {
deleteGist,
fetchGist,
fetchGists,
insertGist,
updateGist,
} from "./db.ts";
export async function createGist(content: string): Promise<IGist> {
const values = {
content,
created_at: new Date(),
};
const _id = await insertGist(values);
return {
_id,
...values,
};
}
export function getGists(skip: number, limit: number): Promise<IGist[]> {
return fetchGists(skip, limit);
}
export function getGist(id: string): Promise<IGist> {
return fetchGist(id);
}
export function removeGist(id: string): Promise<number> {
return deleteGist(id);
}
export function patchGist(id: string, content: string): Promise<{ modifiedCount: number }> {
return updateGist({ id, content });
}
interface IGist {
_id: string;
content: string;
created_at: Date;
}