refactor: document endpoints

This commit is contained in:
Anton Voylenko 2024-12-07 01:02:50 +02:00
commit 8263ffb942
9 changed files with 1696 additions and 1022 deletions

View file

@ -119,20 +119,11 @@ const sendMessage = async (req, res) => {
break
}
default:
return sendErrorResponse(res, 404, 'contentType invalid, must be string, MessageMedia, MessageMediaFromURL, Location, Buttons, List, Contact or Poll')
return sendErrorResponse(res, 400, 'contentType invalid, must be string, MessageMedia, MessageMediaFromURL, Location, Buttons, List, Contact or Poll')
}
res.json({ success: true, message: messageOut })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
console.log(error)
sendErrorResponse(res, 500, error.message)
}
@ -157,15 +148,6 @@ const getClassInfo = (req, res) => {
const sessionInfo = client.info
res.json({ success: true, sessionInfo })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -205,15 +187,6 @@ const isRegisteredUser = async (req, res) => {
const result = await client.isRegisteredUser(number)
res.json({ success: true, result })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -254,15 +227,6 @@ const getNumberId = async (req, res) => {
const result = await client.getNumberId(number)
res.json({ success: true, result })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -318,15 +282,6 @@ const createGroup = async (req, res) => {
}
res.json({ success: true, response })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -354,7 +309,7 @@ const setStatus = async (req, res) => {
status: {
type: 'string',
description: 'New status message',
example: 'I\'m running WhatsApp Web Api'
example: 'I\'m running WWebJS Api'
},
}
},
@ -366,15 +321,6 @@ const setStatus = async (req, res) => {
await client.setStatus(status)
res.json({ success: true })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -397,15 +343,6 @@ const getContacts = async (req, res) => {
const contacts = await client.getContacts()
res.json({ success: true, contacts })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -433,15 +370,6 @@ const getChats = async (req, res) => {
const chats = await client.getChats()
res.json({ success: true, chats })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -481,15 +409,6 @@ const getProfilePictureUrl = async (req, res) => {
const result = await client.getProfilePicUrl(contactId)
res.json({ success: true, result })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -530,15 +449,6 @@ const acceptInvite = async (req, res) => {
const acceptInvite = await client.acceptInvite(inviteCode)
res.json({ success: true, acceptInvite })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -564,15 +474,6 @@ const getWWebVersion = async (req, res) => {
const result = await client.getWWebVersion()
res.json({ success: true, result })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -613,15 +514,6 @@ const archiveChat = async (req, res) => {
const result = await client.archiveChat(chatId)
res.json({ success: true, result })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -646,15 +538,6 @@ const getBlockedContacts = async (req, res) => {
const blockedContacts = await client.getBlockedContacts()
res.json({ success: true, blockedContacts })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -693,20 +576,10 @@ const getChatById = async (req, res) => {
const client = sessions.get(req.params.sessionId)
const chat = await client.getChatById(chatId)
if (!chat) {
sendErrorResponse(res, 404, 'Chat not Found')
return
throw new Error('Chat not found')
}
res.json({ success: true, chat })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -746,15 +619,6 @@ const getChatLabels = async (req, res) => {
const chatLabels = await client.getChatLabels(chatId)
res.json({ success: true, chatLabels })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -794,15 +658,6 @@ const getChatsByLabelId = async (req, res) => {
const chats = await client.getChatsByLabelId(labelId)
res.json({ success: true, chats })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -842,15 +697,6 @@ const getCommonGroups = async (req, res) => {
const groups = await client.getCommonGroups(contactId)
res.json({ success: true, groups })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -889,15 +735,6 @@ const getContactById = async (req, res) => {
const contact = await client.getContactById(contactId)
res.json({ success: true, contact })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -937,15 +774,6 @@ const getInviteInfo = async (req, res) => {
const inviteInfo = await client.getInviteInfo(inviteCode)
res.json({ success: true, inviteInfo })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -985,15 +813,6 @@ const getLabelById = async (req, res) => {
const label = await client.getLabelById(labelId)
res.json({ success: true, label })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -1017,15 +836,6 @@ const getLabels = async (req, res) => {
const labels = await client.getLabels()
res.json({ success: true, labels })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -1067,15 +877,6 @@ const addOrRemoveLabels = async (req, res) => {
await client.addOrRemoveLabels(labelIds, chatIds)
res.json({ success: true })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -1099,15 +900,6 @@ const getState = async (req, res) => {
const state = await client.getState()
res.json({ success: true, state })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -1147,15 +939,6 @@ const markChatUnread = async (req, res) => {
await client.markChatUnread(chatId)
res.json({ success: true })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -1206,15 +989,6 @@ const muteChat = async (req, res) => {
}
res.json({ success: true })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -1254,15 +1028,6 @@ const pinChat = async (req, res) => {
const result = await client.pinChat(chatId)
res.json({ success: true, result })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -1295,7 +1060,7 @@ const searchMessages = async (req, res) => {
options: {
type: 'object',
description: 'Search options',
example: {}
example: { limit: 10, page: 1 }
},
}
},
@ -1312,15 +1077,6 @@ const searchMessages = async (req, res) => {
}
res.json({ success: true, messages })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -1344,15 +1100,6 @@ const sendPresenceAvailable = async (req, res) => {
await client.sendPresenceAvailable()
res.json({ success: true })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -1376,15 +1123,6 @@ const sendPresenceUnavailable = async (req, res) => {
await client.sendPresenceUnavailable()
res.json({ success: true })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -1423,15 +1161,6 @@ const sendSeen = async (req, res) => {
const result = await client.sendSeen(chatId)
res.json({ success: true, result })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -1471,15 +1200,6 @@ const setDisplayName = async (req, res) => {
const result = await client.setDisplayName(displayName)
res.json({ success: true, result })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -1518,15 +1238,6 @@ const unarchiveChat = async (req, res) => {
const result = await client.unarchiveChat(chatId)
res.json({ success: true, result })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -1566,15 +1277,6 @@ const unmuteChat = async (req, res) => {
const result = await client.unmuteChat(chatId)
res.json({ success: true, result })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -1614,15 +1316,6 @@ const unpinChat = async (req, res) => {
const result = await client.unpinChat(chatId)
res.json({ success: true, result })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -1667,15 +1360,6 @@ const setProfilePicture = async (req, res) => {
const result = await client.setProfilePicture(media)
res.json({ success: true, result })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -1697,15 +1381,6 @@ const deleteProfilePicture = async (req, res) => {
const result = await client.deleteProfilePicture()
res.json({ success: true, result })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -1741,15 +1416,6 @@ const setAutoDownloadAudio = async (req, res) => {
await client.setAutoDownloadAudio(flag)
res.json({ success: true })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -1785,15 +1451,6 @@ const setAutoDownloadDocuments = async (req, res) => {
await client.setAutoDownloadDocuments(flag)
res.json({ success: true })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -1829,15 +1486,6 @@ const setAutoDownloadPhotos = async (req, res) => {
await client.setAutoDownloadPhotos(flag)
res.json({ success: true })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -1873,15 +1521,6 @@ const setAutoDownloadVideos = async (req, res) => {
await client.setAutoDownloadVideos(flag)
res.json({ success: true })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -1921,15 +1560,6 @@ const syncHistory = async (req, res) => {
const result = await client.syncHistory(chatId)
res.json({ success: true, result })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -1970,15 +1600,6 @@ const getContactDeviceCount = async (req, res) => {
const result = await client.getContactDeviceCount(userId)
res.json({ success: true, result })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -2018,15 +1639,6 @@ const getCountryCode = async (req, res) => {
const result = await client.getCountryCode(number)
res.json({ success: true, result })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}
@ -2066,15 +1678,6 @@ const getFormattedNumber = async (req, res) => {
const result = await client.getFormattedNumber(number)
res.json({ success: true, result })
} catch (error) {
/* #swagger.responses[500] = {
description: "Server Failure.",
content: {
"application/json": {
schema: { "$ref": "#/definitions/ErrorResponse" }
}
}
}
*/
sendErrorResponse(res, 500, error.message)
}
}