Skip to content

Commit 593a19c

Browse files
committed
lint: lib/note/index.ts
- add typing annotate
1 parent f0121eb commit 593a19c

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

lib/note/index.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {Request, Response} from "express";
12
import config from "../config";
23
import {logger} from "../logger";
34

@@ -63,7 +64,7 @@ async function createNote(userId, noteAlias) {
6364
}
6465

6566
// controller
66-
export async function showNote(req, res) {
67+
export async function showNote(req: Request, res: Response): Promise<void> {
6768
const noteId = req.params.noteId
6869
const userId = req.user ? req.user.id : null
6970

@@ -101,7 +102,7 @@ function canViewNote(note, isLogin, userId) {
101102
return true
102103
}
103104

104-
export async function showPublishNote(req, res) {
105+
export async function showPublishNote(req: Request, res: Response): Promise<void> {
105106
const shortid = req.params.shortid
106107

107108
const note = await getNoteById(shortid, {
@@ -155,7 +156,7 @@ export async function showPublishNote(req, res) {
155156
res.render('pretty.ejs', data)
156157
}
157158

158-
export async function noteActions(req, res) {
159+
export async function noteActions(req: Request, res: Response): Promise<void> {
159160
const noteId = req.params.noteId
160161

161162
const note = await getNoteById(noteId)
@@ -231,7 +232,7 @@ async function getMyNoteList(userId, callback) {
231232
}
232233
}
233234

234-
export function listMyNotes(req, res) {
235+
export function listMyNotes(req: Request, res: Response): void {
235236
if (req.isAuthenticated()) {
236237
getMyNoteList(req.user.id, (err, myNoteList) => {
237238
if (err) return errorInternalError(req, res)
@@ -245,7 +246,7 @@ export function listMyNotes(req, res) {
245246
}
246247
}
247248

248-
export const deleteNote = async (req, res) => {
249+
export async function deleteNote(req: Request, res: Response): Promise<void> {
249250
if (req.isAuthenticated()) {
250251
const noteId = await Note.parseNoteIdAsync(req.params.noteId)
251252
try {
@@ -279,7 +280,7 @@ export const deleteNote = async (req, res) => {
279280
}
280281
}
281282

282-
export const updateNote = async (req, res) => {
283+
export async function updateNote(req: Request, res: Response): Promise<void> {
283284
if (req.isAuthenticated() || config.allowAnonymousEdits) {
284285
const noteId = await Note.parseNoteIdAsync(req.params.noteId)
285286
try {
@@ -295,7 +296,8 @@ export const updateNote = async (req, res) => {
295296

296297
if (realtime.isNoteExistsInPool(noteId)) {
297298
logger.error('Update note failed: There are online users opening this note.')
298-
return res.status('403').json({status: 'error', message: 'Update API can only be used when no users is online'})
299+
res.status(403).json({status: 'error', message: 'Update API can only be used when no users is online'})
300+
return
299301
}
300302

301303
const now = Date.now()

0 commit comments

Comments
 (0)