Skip to content

Commit e2958e8

Browse files
James TsaiJames Tsai
authored andcommitted
refactor: typing for create note options
1 parent bf4bd48 commit e2958e8

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

src/commands/notes/create.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CreateNoteOptions } from '@hackmd/api/dist/type'
1+
import { CommentPermissionType, CreateNoteOptions, NotePermissionRole } from '@hackmd/api/dist/type'
22
import {CliUx, Command, Flags} from '@oclif/core'
33

44
import {APIClient} from '../../api'
@@ -25,10 +25,16 @@ raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q
2525

2626
async run() {
2727
const {flags} = await this.parse(Create)
28-
const options = {...flags}
28+
const options: CreateNoteOptions = {
29+
title: flags.title,
30+
content: flags.content,
31+
readPermission: flags.readPermission as NotePermissionRole,
32+
writePermission: flags.writePermission as NotePermissionRole,
33+
commentPermission: flags.commentPermission as CommentPermissionType
34+
}
2935

3036
try {
31-
const note = await APIClient.createNote(options as CreateNoteOptions)
37+
const note = await APIClient.createNote(options)
3238

3339
CliUx.ux.table([note], {
3440
id: {

src/commands/team-notes/create.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CreateNoteOptions } from '@hackmd/api/dist/type'
1+
import { CommentPermissionType, CreateNoteOptions, NotePermissionRole } from '@hackmd/api/dist/type'
22
import {CliUx, Command, Flags} from '@oclif/core'
33

44
import {APIClient} from '../../api'
@@ -26,15 +26,21 @@ raUuSTetT5uQbqQfLnz9lA A new note gvfz2UB5THiKABQJQnLs6Q n
2626

2727
async run() {
2828
const {flags} = await this.parse(Create)
29-
const {teamPath, title, content, readPermission, writePermission, commentPermission} = flags
30-
const options = {title, content, readPermission, writePermission, commentPermission}
29+
const {teamPath} = flags
30+
const options: CreateNoteOptions = {
31+
title: flags.title,
32+
content: flags.content,
33+
readPermission: flags.readPermission as NotePermissionRole,
34+
writePermission: flags.writePermission as NotePermissionRole,
35+
commentPermission: flags.commentPermission as CommentPermissionType
36+
}
3137

3238
if (!teamPath) {
3339
this.error('Flag teamPath could not be empty')
3440
}
3541

3642
try {
37-
const note = await APIClient.createTeamNote(teamPath, options as CreateNoteOptions)
43+
const note = await APIClient.createTeamNote(teamPath, options)
3844

3945
CliUx.ux.table([note], {
4046
id: {

0 commit comments

Comments
 (0)