1
+ import { Request , Response } from "express" ;
1
2
import config from "../config" ;
2
3
import { logger } from "../logger" ;
3
4
@@ -63,7 +64,7 @@ async function createNote(userId, noteAlias) {
63
64
}
64
65
65
66
// controller
66
- export async function showNote ( req , res ) {
67
+ export async function showNote ( req : Request , res : Response ) : Promise < void > {
67
68
const noteId = req . params . noteId
68
69
const userId = req . user ? req . user . id : null
69
70
@@ -101,7 +102,7 @@ function canViewNote(note, isLogin, userId) {
101
102
return true
102
103
}
103
104
104
- export async function showPublishNote ( req , res ) {
105
+ export async function showPublishNote ( req : Request , res : Response ) : Promise < void > {
105
106
const shortid = req . params . shortid
106
107
107
108
const note = await getNoteById ( shortid , {
@@ -155,7 +156,7 @@ export async function showPublishNote(req, res) {
155
156
res . render ( 'pretty.ejs' , data )
156
157
}
157
158
158
- export async function noteActions ( req , res ) {
159
+ export async function noteActions ( req : Request , res : Response ) : Promise < void > {
159
160
const noteId = req . params . noteId
160
161
161
162
const note = await getNoteById ( noteId )
@@ -231,7 +232,7 @@ async function getMyNoteList(userId, callback) {
231
232
}
232
233
}
233
234
234
- export function listMyNotes ( req , res ) {
235
+ export function listMyNotes ( req : Request , res : Response ) : void {
235
236
if ( req . isAuthenticated ( ) ) {
236
237
getMyNoteList ( req . user . id , ( err , myNoteList ) => {
237
238
if ( err ) return errorInternalError ( req , res )
@@ -245,7 +246,7 @@ export function listMyNotes(req, res) {
245
246
}
246
247
}
247
248
248
- export const deleteNote = async ( req , res ) = > {
249
+ export async function deleteNote ( req : Request , res : Response ) : Promise < void > {
249
250
if ( req . isAuthenticated ( ) ) {
250
251
const noteId = await Note . parseNoteIdAsync ( req . params . noteId )
251
252
try {
@@ -279,7 +280,7 @@ export const deleteNote = async (req, res) => {
279
280
}
280
281
}
281
282
282
- export const updateNote = async ( req , res ) = > {
283
+ export async function updateNote ( req : Request , res : Response ) : Promise < void > {
283
284
if ( req . isAuthenticated ( ) || config . allowAnonymousEdits ) {
284
285
const noteId = await Note . parseNoteIdAsync ( req . params . noteId )
285
286
try {
@@ -295,7 +296,8 @@ export const updateNote = async (req, res) => {
295
296
296
297
if ( realtime . isNoteExistsInPool ( noteId ) ) {
297
298
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
299
301
}
300
302
301
303
const now = Date . now ( )
0 commit comments