Best JavaScript code snippet using wpt
Api.js
Source:Api.js
...114 });115 },116 // ë¡ê·¸ìì117 getLogout: async() => {118 return await getRequest('/auth/logout');119 },120 // ìì´ë ì¤ë³µ íì¸121 getDoubleCheckId: async(loginId) => {122 return await getRequest('/auth/doubleId', { loginId });123 },124 // ì´ë©ì¼ ì¸ì¦ ë²í¸ ì ì¡125 getEmail: async(email) => {126 return await getRequest('/auth/email', { email });127 },128 // ë¹ë°ë²í¸ ì¬ì¤ì ì´ë©ì¼ ì¸ì¦ ì ì¡129 getResetPasswordEmail: async(email) => {130 return await getRequest('/auth/email/password', { email });131 },132 // ì´ë©ì¼ ì¸ì¦ ë²í¸ íì¸133 postEmail: async(emailId, authStr) => {134 return await postJsonReqest('/auth/email', { emailId, authStr });135 },136 // ë¹ë°ë²í¸ ì¬ì¤ì 137 postPassword: async(loginId, changePassword) => {138 return await postJsonReqest('/auth/password', { loginId, changePassword });139 },140 // User--------------------------------------------------------------------------141 // íìê°ì
142 postUser: async(user_data) => {143 return await postJsonReqest('/user', user_data);144 },145 // íìì ë³´ ìì 146 postUpdateUser: async(147 userId,148 user_image,149 user_introduction,150 user_github,151 user_blog,152 user_position153 ) => {154 return await postJsonReqest(`/user/${userId}`, {155 user_image,156 user_introduction,157 user_github,158 user_blog,159 user_position160 });161 },162 // íìì ë³´ ì¡°í163 getReaduser: async(userId) => {164 return await getRequest(`/user/${userId}`);165 },166 // ì¬ì©ì LoginIdê²ì167 getUserLoginId: async(loginId) => {168 return await getRequest('/user/search/loginId', { loginId });169 },170 // êµìë 리ì¤í¸ ì¡°í171 getProfessors: async() => {172 return await getRequest('/user/professors');173 },174 // ì¬ì©ì ì°¸ê° íë¡ì í¸ ë¦¬ì¤í¸ ì¡°í175 getProjectInUser: async(userId, pageNum, pageCount) => {176 return await getRequest(`/user/${userId}/projects`, { pageNum, pageCount });177 },178 // ë´ê° ìì±í íì모ì§ê¸ ì¡°í179 getUserRecruitment: async(userId, pageNum, pageCount) => {180 return await getRequest(`/user/${userId}/recruitment`, {181 pageNum,182 pageCount183 });184 },185 // íì íí´186 deleteUser: async(userId) => {187 return await deleteJsonReqest(`/user/${userId}`);188 },189 // Projects--------------------------------------------------------------------------------190 // íë¡ì í¸ ìì±191 postProject: async(project) => {192 return await postJsonReqest('/project', project);193 },194 // íë¡ì í¸ ìì 195 postUpdateProject: async(projectId, project) => {196 return await postJsonReqest(`/project/${projectId}`, project);197 },198 // íë¡ì í¸ ìì¸ì¡°í199 getProject: async(projectId) => {200 return await getRequest(`/project/${projectId}`);201 },202 // íë¡ì í¸ ì ì²´ì¡°í203 getAllProject: async(pageNum, pageCount) => {204 return await getRequest('/project', { pageNum, pageCount });205 },206 // ì ì²´ íë¡ì í¸ ê°ì ì¡°í207 getAllProjectCount: async() => {208 return await getRequest('/project-count');209 },210 // íë¡ì í¸ ì¡°íì ì¦ê°211 getHit: async(projectId) => {212 return await getRequest(`/project/${projectId}/hit`);213 },214 // íë¡ì í¸ ì ì²´ 기ì ì¤í 리ì¤í¸ ì¡°í215 getStacks: async() => {216 const stack = await getRequest('/project/tags');217 return await getRequest('/project/tags');218 },219 // íë¡ì í¸ ì¹´í
ê³ ë¦¬ 리ì¤í¸ ì¡°í220 getCategorys: async() => {221 return await getRequest('/project/categorys');222 },223 // íë¡ì í¸ ê³¼ëª©ë
ë 리ì¤í¸ ì¡°í224 getYears: async() => {225 return await getRequest('/project/subject-years');226 },227 // íë¡ì í¸ ê³¼ëª©ë¦¬ì¤í¸ ì¡°í228 getSubjects: async() => {229 return await getRequest('/project/subjects');230 },231 // íë¡ì í¸ ì ë ¬ ë©ë´ ì¡°í232 getMenus: () => {233 return ['ìµì ì', 'ì¢ììì', 'ì¡°íì'];234 },235 // íë¡ì í¸ íê·¸ ê²ì236 getProjectTags: async(tagId) => {237 return await getRequest(`/project/search/tag?tagId=${tagId}`);238 },239 // ì¹´í
ê³ ë¦¬ë³ íë¡ì í¸ ì¡°í240 getProjectInCategory: async(categoryId, pageNum, pageCount) => {241 const response = await getRequest('/project/search/category', {242 categoryId,243 pageNum,244 pageCount245 });246 return response.data;247 },248 // íë¡ì í¸ ê²ì249 postProjectSearch: async(pageNum, pageCount, project) => {250 return await postJsonReqest(251 `/project/search/?pageNum=${pageNum}&pageCount=${pageCount}`,252 project253 );254 },255 // íë¡ì í¸ ìì 256 deleteProject: async(projectId) => {257 return await deleteJsonReqest(`/project/${projectId}`);258 },259 // Follow------------------------------------------------------------------------------------260 // íë¡ì°261 getFollow: async(targetId) => {262 return await getRequest('/user/follow', { targetId });263 },264 // íë¡ì° ì·¨ì265 getUnfollow: async(targetId) => {266 return await getRequest('/user/unfollow', { targetId });267 },268 // íë¡ì 리ì¤í¸ ì¡°í269 getFollowerList: async(userId) => {270 return await getRequest(`/user/${userId}/followers`);271 },272 // íë¡ì 리ì¤í¸ ì¡°í273 getFollowingList: async(userId) => {274 return await getRequest(`/user/${userId}/followings`);275 },276 // likes------------------------------------------------------------------------------------277 // íë¡ì í¸ ì¢ìì ì¬ë¶ íì¸278 getProjectIsLike: async(projectId) => {279 return await getRequest('/project/isLike', { projectId });280 },281 // íë¡ì í¸ ì¢ìì282 getProjectLike: async(projectId) => {283 return await getRequest('/project/like', { projectId });284 },285 // íë¡ì í¸ ì¢ìì ì·¨ì286 getProjectUnlike: async(projectId) => {287 return await getRequest('/project/unlike', { projectId });288 },289 // ì¬ì©ìì ì¢ììí íë¡ì í¸ ë¦¬ì¤í¸ ì¡°í290 getLikedProject: async(userId, pageNum, pageCount) => {291 return await getRequest(`/user/${userId}/like-projects`, {292 pageNum,293 pageCount294 });295 },296 // Posts------------------------------------------------------------------------------------297 // ê²ìê¸ ìì±298 getCreatePosting: async(projectId, post_title, post_content) => {299 return await postJsonReqest(`/project/${projectId}/post`, {300 post_title,301 post_content302 });303 },304 // ê²ìê¸ ìì 305 postUpdatePosting: async(projectId, postId, postObject) => {306 return await postJsonReqest(307 `/project/${projectId}/post/${postId}`,308 postObject309 );310 },311 // ê²ìê¸ ìì -> ìì§ êµ¬í X312 deletePosting: async(projectId, postId) => {313 return await deleteJsonReqest(`/project/${projectId}/post/${postId}`);314 },315 // ê²ìê¸ ì¡°í316 getReadPosting: async(projectId, postId) => {317 return await getRequest(`/project/${projectId}/post/${postId}`);318 },319 // ê²ìê¸ ëª©ë¡ ì¡°í320 getPostingList: async(projectId) => {321 return await getRequest(`/project/${projectId}/post-list`);322 },323 // Comments-----------------------------------------------------------------------------------324 // íë¡ì í¸ì ëê¸ / ëëê¸ ë±ë¡325 postComment: async(326 projectId,327 comment_content,328 comment_depth,329 comment_parent330 ) => {331 return await postJsonReqest(`/project/${projectId}/comment`, {332 comment_content,333 comment_depth,334 comment_parent335 });336 },337 // íë¡ì í¸ì ëê¸ / ëëê¸ ìì 338 postUpdateComment: async(projectId, commentId, comment_content) => {339 return await postJsonReqest(`/project/${projectId}/comment/${commentId}`, {340 comment_content341 });342 },343 // íë¡ì í¸ì ëê¸ / ëëê¸ ìì 344 deleteComment: async(projectId, commentId) => {345 return await deleteJsonReqest(`/project/${projectId}/comment/${commentId}`);346 },347 // íë¡ì í¸ì ëê¸ / ëëê¸ ì¡°í348 getReadComment: async(projectId) => {349 return await getRequest(`/project/${projectId}/comment/`);350 },351 // Files--------------------------------------------------------------------------------------352 getReadFile: async(fileData) => {353 return await postFormReqest(`/file/upload`, fileData);354 },355 getReadFilePDF: async(fileData) => {356 return await postFormReqest(`/file/uploadPDF`, fileData);357 },358 // Recruitment--------------------------------------------------------------------------------359 postTeam: async(Team) => {360 return await postJsonReqest('/recruitment', Team);361 },362 getAllTeam: async(pageNum, pageCount) => {363 const response = await getRequest('/recruitment', { pageNum, pageCount });364 return response.data;365 },366 getTeam: async(Teamid) => {367 return await getRequest(`/recruitment/${Teamid}`);368 },369 getTeamEnd: async(Teamid) => {370 return await getRequest(`/recruitment/${Teamid}/end`);371 },372 getTeamApplication: async(Teamid) => {373 return await getRequest(`/recruitment/${Teamid}/application`);374 },375 postTeamUpdate: async(Teamid, Team) => {376 return await postJsonReqest(`/recruitment/${Teamid}`, Team);377 },378 deleteTeam: async(Teamid) => {379 return await deleteJsonReqest(`/recruitment/${Teamid}`);380 },381 getSearch: async(pageNum, pageCount, keyword, subject) => {382 const response = await getRequest(383 `/recruitment/search?pageNum=${pageNum}&pageCount=${pageCount}&keyword=${keyword}&subject=${subject}`384 );385 return response.data;386 },387 getTeamcancelApplication: async(Teamid) => {388 return await deleteJsonReqest(`/recruitment/${Teamid}/application`);389 },390 getTeamList: async(Teamid) => {391 return await getRequest(`/recruitment/${Teamid}/application-list`);392 },393 getisApplication: async(Teamid) => {394 return await getRequest(`/recruitment/${Teamid}/isApplication`);395 },396 getOK: async(Teamid, array) => {397 return await getRequest(`/recruitment/${Teamid}/accept?userId=${array}`);398 },399 getRefuse: async(Teamid, array) => {400 return await getRequest(`/recruitment/${Teamid}/refuse?userId=${array}`);401 }402 // Notificationâââââââââââââââââââââââââââââââââââââââ403};...
PostModel.js
Source:PostModel.js
1const sql = require("./ConnectMySQL");2require('dotenv').config();3const { GetUUID, GetProfileById } = require('./AuthModel');4const { CreateContentPromise, GetContentByPostPromise } = require('./ContentModel');5const { CreateImagePromise, GetImageByPostPromise, GetImageByIDPromise } = require('./ImageModel');6const { GetVoteByPostPromise } = require('./VoteModel');7const { GetCommentByPostPromise } = require('./CommentModel');8const GetPostPromise = async (getRequest) => {9 return new Promise((resolve, reject) => {10 sql.query(11 `SELECT tb_post.postID, tb_post.userID, tb_post.postCreatedAt12 FROM tb_post13 ORDER BY tb_post.postCreatedAt DESC `,14 [getRequest.start, getRequest.limit],15 (err, data) => {16 if (err) {17 reject(new Error("Failed to get post"));18 } else {19 data.forEach(item => {20 item.postCreatedAt = item.postCreatedAt.toString();21 });22 resolve(data);23 }24 }25 );26 })27};28module.exports.Get = async (getRequest, result) => {29 try {30 const postResponse = await GetPostPromise(getRequest);31 for (let i = 0; i < postResponse.length; i++) {32 const item = postResponse[i];33 const [contentResponse, imageResponse, userResponse, voteResponse] = await Promise.all([34 GetContentByPostPromise({ postID: item.postID }),35 GetImageByPostPromise({ postID: item.postID }),36 GetProfileById({ userID: item.userID }),37 GetVoteByPostPromise({ postID: item.postID }),38 ]);39 item.voteAVG = voteResponse.reduce((acc, item) => { return (acc + item.voteValue) }, 0) / voteResponse.length || 0;40 item.content = contentResponse;41 item.vote = voteResponse;42 item.user = userResponse;43 item.image = imageResponse;44 }45 result(null, postResponse);46 } catch (error) {47 result(error, null);48 }49};50const GetPostByUserPromise = async (getRequest) => {51 return new Promise((resolve, reject) => {52 sql.query(53 `SELECT tb_post.postID, tb_post.userID, tb_post.postCreatedAt54 FROM tb_post55 WHERE tb_post.userID = ?56 ORDER BY tb_post.postCreatedAt DESC `,57 [getRequest.userID, getRequest.start, getRequest.limit],58 (err, data) => {59 if (err) {60 reject(new Error("Failed to get post"));61 } else {62 data.forEach(item => {63 item.postCreatedAt = item.postCreatedAt.toString();64 });65 resolve(data);66 }67 }68 );69 })70};71module.exports.GetByUser = async (getRequest, result) => {72 try {73 const postResponse = await GetPostByUserPromise(getRequest);74 for (let i = 0; i < postResponse.length; i++) {75 const item = postResponse[i];76 const [contentResponse, imageResponse, userResponse, voteResponse] = await Promise.all([77 GetContentByPostPromise({ postID: item.postID }),78 GetImageByPostPromise({ postID: item.postID }),79 GetProfileById({ userID: item.userID }),80 GetVoteByPostPromise({ postID: item.postID }),81 ]);82 item.voteAVG = voteResponse.reduce((acc, item) => { return (acc + item.voteValue) }, 0) / voteResponse.length || 0;83 item.content = contentResponse;84 item.vote = voteResponse;85 item.user = userResponse;86 item.image = imageResponse;87 }88 result(null, postResponse);89 } catch (error) {90 result(error, null);91 }92};93const GetPostByIDPromise = async (getRequest) => {94 return new Promise((resolve, reject) => {95 sql.query(96 `SELECT tb_post.postID, tb_post.userID, tb_post.postCreatedAt97 FROM tb_post98 WHERE tb_post.postID = ?`,99 [getRequest.postID],100 (err, data) => {101 if (err) {102 reject(new Error("Failed to get post"));103 } else {104 data.forEach(item => {105 item.postCreatedAt = item.postCreatedAt.toString();106 });107 resolve(data);108 }109 }110 );111 })112};113module.exports.GetByID = async (getRequest, result) => {114 try {115 const postResponse = await GetPostByIDPromise(getRequest);116 for (let i = 0; i < postResponse.length; i++) {117 const item = postResponse[i];118 const [contentResponse, imageResponse, userResponse, voteResponse] = await Promise.all([119 GetContentByPostPromise({ postID: item.postID }),120 GetImageByPostPromise({ postID: item.postID }),121 GetProfileById({ userID: item.userID }),122 GetVoteByPostPromise({ postID: item.postID }),123 ]);124 item.voteAVG = voteResponse.reduce((acc, item) => { return (acc + item.voteValue) }, 0) / voteResponse.length;125 item.content = contentResponse;126 item.vote = voteResponse;127 item.user = userResponse;128 item.image = imageResponse;129 }130 result(null, postResponse);131 } catch (error) {132 result(error, null);133 }134};135const CreatePostPromise = async (getRequest) => {136 return new Promise((resolve, reject) => {137 sql.query(138 `INSERT INTO tb_post (tb_post.postID, tb_post.userID, tb_post.postCreatedAt) VALUES (?, ?, ?)`,139 [getRequest.uuid, getRequest.userID, getRequest.postCreatedAt],140 (err, data) => {141 if (err) {142 reject(new Error("Failed to upload post"));143 } else if (data) {144 resolve({ postID: getRequest.uuid, ...data });145 }146 }147 );148 })149}150module.exports.Create = async (getRequest, result) => {151 try {152 console.log("tạo", getRequest);153 const uuid = await GetUUID();154 if (!getRequest.postCreatedAt) {155 getRequest.postCreatedAt = new Date();156 }157 const postResponse = await CreatePostPromise({ ...getRequest, uuid });158 if (getRequest.contentText && getRequest.filepath) {159 console.log("Äủ ảnh, chữ");160 const [contentResponse, imageResponse] = await Promise.all([161 CreateContentPromise({ ...getRequest, postID: postResponse.postID }),162 CreateImagePromise({ ...getRequest, postID: postResponse.postID }),163 ]);164 result(null, { postResponse, contentResponse });165 } else {166 if (getRequest.contentText) {167 console.log("chá» chữ");168 const contentResponse = await CreateContentPromise({ ...getRequest, postID: postResponse.postID });169 result(null, { postResponse, contentResponse });170 }171 if (getRequest.filepath) {172 console.log("chỠảnh")173 const imageResponse = await CreateImagePromise({ ...getRequest, postID: postResponse.postID });174 result(null, { postResponse, imageResponse });175 }176 }177 } catch (error) {178 result(error, null);179 }180};181module.exports.DeleteByID = async (getRequest, result) => {182 sql.query(183 `DELETE FROM tb_post WHERE tb_post.postID = ?`,184 [getRequest.postID],185 (err, data) => {186 if (err) {187 result(err, null)188 } else {189 result(null, { ...data });190 }191 }192 );...
champion-model.js
Source:champion-model.js
1var api_key = 'b9f2effe-c90e-4633-b36b-5716684ccbac' //should these lines have semi-colons? -tcj2var FREE_CHAMPS_URL= 'https://na.api.pvp.net/api/lol/na/v1.2/champion?freeToPlay=true&api_key=' + api_key //should these lines have semi-colons? -tcj3var CHALLENGER_URL = 'https://na.api.pvp.net/api/lol/na/v2.5/league/challenger?type=RANKED_SOLO_5x5&api_key=' + api_key //should these lines have semi-colons? -tcj4var MH_URL_1 = 'https://na.api.pvp.net/api/lol/na/v2.2/matchhistory/'5var MH_URL_2 = '?api_key=' + api_key //should these lines have semi-colons? -tcj6var ITEM_URL_1 = 'https://global.api.pvp.net/api/lol/static-data/na/v1.2/item/'7var ITEM_URL_2 = '?itemData=image&api_key=' + api_key8var CHAMP_URL_1 = 'https://global.api.pvp.net/api/lol/static-data/na/v1.2/champion/'9var CHAMP_URL_2 = '?api_key=' + api_key10var VERSION_URL = 'https://global.api.pvp.net/api/lol/static-data/na/v1.2/versions?api_key=' + api_key11var STATUS_OK = 200;12var XMLHttpRequest = require('xhr2')13var fs = require('fs')14exports.freeChamps = function(callback) {15 var getRequest = new XMLHttpRequest();16 getRequest.addEventListener('load', function(event){17 if (getRequest.status != STATUS_OK){18 callback(getRequest.responseText);19 }20 else{21 var JSONPosts = getRequest.responseText;22 var parsedPosts = JSON.parse(JSONPosts);23 return callback(null, parsedPosts);24 }25 });26 getRequest.open('GET', FREE_CHAMPS_URL);27 getRequest.send();28},29exports.challengers = function(callback,champs, champItems) {30 var getRequest = new XMLHttpRequest();31 getRequest.addEventListener('load', function(event, champs, champItems){32 if (getRequest.status != STATUS_OK){33 console.log(getRequest)34 callback(getRequest.responseText);35 }36 else{37 var JSONPosts = getRequest.responseText;38 var parsedPosts = JSON.parse(JSONPosts);39 return callback(null, parsedPosts, champs, champItems);40 }41 });42 getRequest.open('GET', CHALLENGER_URL);43 getRequest.send();44},45exports.matchHistory = function(callback, summonerID) {46 var getRequest = new XMLHttpRequest();47 getRequest.addEventListener('load', function(event){48 if (getRequest.status != STATUS_OK){49 callback(getRequest.responseText);50 }51 else{52 var JSONPosts = getRequest.responseText;53 var parsedPosts = JSON.parse(JSONPosts);54 return callback(null, parsedPosts);55 }56 });57 getRequest.open('GET', MH_URL_1 + summonerID + MH_URL_2);58 getRequest.send();59},60exports.getItem = function(callback, itemID){61 var getRequest = new XMLHttpRequest();62 getRequest.addEventListener('load', function(event){63 if (getRequest.status != STATUS_OK){64 callback(getRequest.responseText);65 }66 else{67 var JSONPosts = getRequest.responseText;68 var parsedPosts = JSON.parse(JSONPosts);69 return callback(null, parsedPosts);70 }71 });72 getRequest.open('GET', ITEM_URL_1 + itemID + ITEM_URL_2);73 getRequest.send();74},75exports.getChamp = function(callback, champID){76 var getRequest = new XMLHttpRequest();77 getRequest.addEventListener('load', function(event){78 if (getRequest.status != STATUS_OK){79 callback(getRequest.responseText);80 }81 else{82 var JSONPosts = getRequest.responseText;83 var parsedPosts = JSON.parse(JSONPosts);84 return callback(null, parsedPosts);85 }86 });87 getRequest.open('GET', CHAMP_URL_1 + champID + CHAMP_URL_2);88 getRequest.send();89},90exports.version = function(callback) {91 var getRequest = new XMLHttpRequest();92 getRequest.addEventListener('load', function(event){93 if (getRequest.status != STATUS_OK){94 callback(getRequest.responseText);95 }96 else{97 var JSONPosts = getRequest.responseText;98 var parsedPosts = JSON.parse(JSONPosts);99 return callback(null, parsedPosts);100 }101 });102 getRequest.open('GET', VERSION_URL);103 getRequest.send();104},105exports.postFatJSON = function(fatJSON) {106 fatJSON = JSON.stringify(fatJSON)107 fs.writeFile('FatJSON.json', fatJSON)...
CommentModel.js
Source:CommentModel.js
1const sql = require("./ConnectMySQL");2const { GetUUID } = require('./AuthModel');3module.exports.GetByID = async (getRequest, result) => {4 sql.query(5 `SELECT tb_comment.commentID, tb_comment.postID, tb_comment.commentText, tb_comment.commentCreatedAt, tb_comment.commentParentID, tb_comment.userID6 FROM tb_comment7 WHERE tb_comment.commentID = ?`,8 [getRequest.commentID],9 (err, data) => {10 if (err) {11 result(err, null);12 } else {13 result(null, data);14 }15 }16 );17};18module.exports.GetByPost = async (getRequest, result) => {19 sql.query(20 `SELECT tb_comment.*, tb_profile.userFirstname, tb_profile.userLastname, tb_image.imageSource21 FROM tb_comment, tb_profile, tb_image22 WHERE tb_comment.userID = tb_profile.userID AND tb_profile.imageID = tb_image.imageID AND tb_comment.postID = ?23 ORDER BY tb_comment.commentCreatedAt ASC`,24 [getRequest.postID],25 (err, data) => {26 if (err) {27 result(err, null)28 } else {29 const dataResponse = [];30 data.forEach(comment => {31 comment.imageSource = process.env.BASE_URL + comment.imageSource;32 if (comment.commentID == comment.commentParentID) {33 comment.replys = [];34 dataResponse.push(comment);35 } else {36 dataResponse.find(item => item.commentID == comment.commentParentID).replys.push(comment);37 }38 })39 result(null, dataResponse);40 }41 }42 );43};44module.exports.GetCommentByPostPromise = async (getRequest) => {45 return new Promise((resolve, reject) => {46 sql.query(47 `SELECT tb_comment.commentID, tb_comment.postID, tb_comment.commentText, tb_comment.commentCreatedAt, tb_comment.commentParentID, tb_comment.userID48 FROM tb_comment49 WHERE tb_comment.postID = ?50 ORDER BY tb_comment.commentCreatedAt ASC`,51 [getRequest.postID],52 (err, data) => {53 if (err) {54 reject(err)55 } else {56 resolve(data);57 }58 }59 );60 })61};62module.exports.Create = async (getRequest, result) => {63 const uuid = await GetUUID();64 if (getRequest.commentParentID == null) {65 getRequest.commentParentID = uuid;66 }67 if (getRequest.commentCreatedAt == null) {68 getRequest.commentCreatedAt = new Date();69 }70 sql.query(71 `INSERT INTO tb_comment (tb_comment.commentID, tb_comment.commentText, tb_comment.commentCreatedAt, tb_comment.postID, tb_comment.commentParentID, tb_comment.userID) VALUES (?, ?, ?, ?, ?, ?)`,72 [uuid, getRequest.commentText, getRequest.commentCreatedAt, getRequest.postID, getRequest.commentParentID, getRequest.userID],73 (err, data) => {74 if (err) {75 result(err, null)76 } else {77 result(null, { commentID: uuid, ...data });78 }79 }80 );81};82module.exports.UpdateByID = async (getRequest, result) => {83 sql.query(84 `UPDATE tb_comment 85 SET tb_comment.commentText = ?86 WHERE tb_comment.commentID = ?`,87 [getRequest.commentText, getRequest.commentID],88 (err, data) => {89 if (err) {90 result(err, null)91 } else {92 result(null, { ...data });93 }94 }95 );96};97module.exports.DeleteByID = async (getRequest, result) => {98 sql.query(99 `DELETE FROM tb_comment WHERE tb_comment.commentID = ?`,100 [getRequest.commentID],101 (err, data) => {102 if (err) {103 result(err, null)104 } else {105 result(null, { ...data });106 }107 }108 );...
ImageModel.js
Source:ImageModel.js
1const sql = require("./ConnectMySQL");2const { GetUUID } = require('./AuthModel');3const upload = require('../multer');4module.exports.GetByID = async (getRequest, result) => {5 sql.query(6 `SELECT tb_image.imageID, tb_image.imageSource, tb_image.postID 7 FROM tb_image8 WHERE tb_image.imageID = ?`,9 [getRequest.imageID],10 (err, data) => {11 if (err) {12 result(err, null)13 } else {14 result(null, data);15 }16 }17 );18};19module.exports.GetByPost = async (getRequest, result) => {20 sql.query(21 `SELECT tb_image.imageID, tb_image.imageSource, tb_image.postID 22 FROM tb_image23 WHERE tb_image.imageID = ?`,24 [getRequest.postID],25 (err, data) => {26 if (err) {27 result(err, null)28 } else {29 result(null, data);30 }31 }32 );33};34module.exports.Create = async (getRequest, result) => {35 const uuid = await GetUUID();36 sql.query(37 `INSERT INTO tb_image (tb_image.imageID, tb_image.imageSource, tb_image.postID) VALUES (?, ?, ?)`,38 [uuid, getRequest.imageSource, getRequest.postID],39 (err, data) => {40 if (err) {41 result(err, null)42 } else {43 result(null, { imageID: uuid, ...data });44 }45 }46 );47};48module.exports.UpdateByID = async (getRequest, result) => {49 sql.query(50 `UPDATE tb_image51 SET tb_image.imageSource = ?52 WHERE tb_image.imageID = ?`,53 [getRequest.imageSource, getRequest.imageID],54 (err, data) => {55 if (err) {56 result(err, null)57 } else {58 result(null, { ...data });59 }60 }61 );62};63module.exports.DeleteByID = async (getRequest, result) => {64 sql.query(65 `DELETE FROM tb_image66 WHERE tb_image.imageID = ?`,67 [getRequest.imageID],68 (err, data) => {69 if (err) {70 result(err, null)71 } else {72 result(null, { ...data });73 }74 }75 );76};77module.exports.CreateImagePromise = async (getRequest) => {78 const uuid = await GetUUID();79 return new Promise((resolve, reject) => {80 sql.query(81 `INSERT INTO tb_image (tb_image.imageID, tb_image.imageSource, tb_image.postID) VALUES (?, ?, ?)`,82 [uuid, getRequest.filepath, getRequest.postID],83 (err, data) => {84 if (err) {85 reject(new Error("Error upload image"));86 } else {87 resolve({ imageID: uuid, ...data });88 }89 }90 );91 })92};93module.exports.GetImageByPostPromise = async (getRequest) => {94 return new Promise((resolve, reject) => {95 sql.query(96 `SELECT tb_image.imageID, tb_image.imageSource97 FROM tb_image98 WHERE tb_image.postID = ?`,99 [getRequest.postID],100 (err, data) => {101 if (err) {102 reject(new Error("Error get image"));103 } else {104 data.forEach(image => {105 image.imageSource = process.env.BASE_URL + image.imageSource;106 })107 resolve(data);108 }109 }110 );111 })112};113module.exports.GetImageByIDPromise = async (getRequest) => {114 return new Promise((resolve, reject) => {115 sql.query(116 `SELECT tb_image.imageID, tb_image.imageSource117 FROM tb_image118 WHERE tb_image.imageID = ?`,119 [getRequest.imageID],120 (err, data) => {121 if (err) {122 reject(new Error("Error get image"));123 } else {124 resolve(data);125 }126 }127 );128 })...
VoteModel.js
Source:VoteModel.js
1const sql = require("./ConnectMySQL");2const { GetUUID } = require('./AuthModel');3module.exports.GetByID = async (getRequest, result) => {4 sql.query(5 `SELECT tb_vote.voteID, tb_vote.voteValue, tb_vote.voteCreatedAt, tb_vote.postID, tb_vote.userID 6 FROM tb_vote7 WHERE tb_vote.voteID = ?`,8 [getRequest.voteID],9 (err, data) => {10 if (err) {11 result(err, null)12 } else {13 result(null, data);14 }15 }16 );17};18module.exports.GetByPost = async (getRequest, result) => {19 sql.query(20 `SELECT tb_vote.voteID, tb_vote.voteValue, tb_vote.voteCreatedAt, tb_vote.postID, tb_vote.userID 21 FROM tb_vote22 WHERE tb_vote.postID = ?23 ORDER BY tb_vote.voteCreatedAt DESC`,24 [getRequest.postID],25 (err, data) => {26 if (err) {27 result(err, null)28 } else {29 result(null, data);30 }31 }32 );33};34module.exports.GetVoteByPostPromise = async (getRequest, result) => {35 return new Promise((resolve, reject) => {36 sql.query(37 `SELECT tb_vote.voteID, tb_vote.voteValue, tb_vote.voteCreatedAt, tb_vote.postID, tb_vote.userID, tb_profile.userFirstname, tb_profile.userLastname 38 FROM tb_vote, tb_profile39 WHERE tb_vote.userID = tb_profile.userID AND tb_vote.postID = ?40 ORDER BY tb_vote.voteCreatedAt DESC`,41 [getRequest.postID],42 (err, data) => {43 if (err) {44 reject(err)45 } else {46 resolve(data);47 }48 }49 );50 })51};52module.exports.GetVoteByPostAndUserPromise = async (getRequest) => {53 return new Promise((resolve, reject) => {54 sql.query(55 `SELECT tb_vote.voteID, tb_vote.voteValue, tb_vote.voteCreatedAt, tb_vote.postID, tb_vote.userID 56 FROM tb_vote57 WHERE tb_vote.postID = ? AND tb_vote.userID = ?58 ORDER BY tb_vote.voteCreatedAt DESC`,59 [getRequest.postID, getRequest.userID],60 (err, data) => {61 if (err) {62 reject(err)63 } else {64 resolve(data);65 }66 }67 );68 })69};70module.exports.Create = async (getRequest, result) => {71 const uuid = await GetUUID();72 if (!getRequest.voteCreatedAt) {73 getRequest.voteCreatedAt = new Date().toISOString().slice(0, 19).replace('T', ' ');74 }75 sql.query(76 `INSERT INTO tb_vote (tb_vote.voteID, tb_vote.voteValue, tb_vote.voteCreatedAt, tb_vote.postID, tb_vote.userID ) VALUES (?, ?, ?, ?, ?)`,77 [uuid, getRequest.voteValue, getRequest.voteCreatedAt, getRequest.postID, getRequest.userID],78 (err, data) => {79 if (err) {80 result(err, null)81 } else {82 result(null, { voteID: uuid, ...data });83 }84 }85 );86};87module.exports.UpdateByID = async (getRequest, result) => {88 sql.query(89 `UPDATE tb_vote 90 SET tb_vote.voteValue = ?91 WHERE tb_vote.voteID = ?`,92 [getRequest.voteValue, getRequest.voteID],93 (err, data) => {94 if (err) {95 result(err, null)96 } else {97 result(null, { ...data });98 }99 }100 );101};102module.exports.DeleteByID = async (getRequest, result) => {103 sql.query(104 `DELETE FROM tb_vote WHERE tb_vote.voteID = ?`,105 [getRequest.voteID],106 (err, data) => {107 if (err) {108 result(err, null)109 } else {110 result(null, { ...data });111 }112 }113 );...
xpCGIVariables.jss
Source:xpCGIVariables.jss
...20 function _get(name) {21 22 switch (name.toUpperCase()) {23 24 case "AUTH_TYPE": return facesContext.getExternalContext().getRequest().getAuthType();25 case "CONTENT_LENGTH": return facesContext.getExternalContext().getRequest().getContentLength();26 case "CONTENT_TYPE": return facesContext.getExternalContext().getRequest().getContentType();27 case "CONTEXT_PATH": return facesContext.getExternalContext().getRequest().getContextPath();28 case "GATEWAY_INTERFACE": return "CGI/1.1";29 case "HTTPS": return facesContext.getExternalContext().getRequest().isSecure() ? "ON" : "OFF";30 case "PATH_INFO": return facesContext.getExternalContext().getRequest().getPathInfo();31 case "PATH_TRANSLATED": return facesContext.getExternalContext().getRequest().getPathTranslated();32 case "QUERY_STRING": return facesContext.getExternalContext().getRequest().getQueryString();33 case "REMOTE_ADDR": return facesContext.getExternalContext().getRequest().getRemoteAddr();34 case "REMOTE_HOST": return facesContext.getExternalContext().getRequest().getRemoteHost();35 case "REMOTE_USER": return facesContext.getExternalContext().getRequest().getRemoteUser();36 case "REQUEST_METHOD": return facesContext.getExternalContext().getRequest().getMethod();37 case "REQUEST_SCHEME": return facesContext.getExternalContext().getRequest().getScheme();38 case "REQUEST_URI": return facesContext.getExternalContext().getRequest().getRequestURI();39 case "SCRIPT_NAME": return facesContext.getExternalContext().getRequest().getServletPath();40 case "SERVER_NAME": return facesContext.getExternalContext().getRequest().getServerName();41 case "SERVER_PORT": return facesContext.getExternalContext().getRequest().getServerPort();42 case "SERVER_PROTOCOL": return facesContext.getExternalContext().getRequest().getProtocol();43 case "SERVER_SOFTWARE": return facesContext.getExternalContext().getContext().getServerInfo();44 45 // these are not really CGI variables, but useful, so lets just add them for convenience46 case "HTTP_ACCEPT": return facesContext.getExternalContext().getRequest().getHeader("Accept");47 case "HTTP_ACCEPT_ENCODING": return facesContext.getExternalContext().getRequest().getHeader("Accept-Encoding");48 case "HTTP_ACCEPT_LANGUAGE": return facesContext.getExternalContext().getRequest().getHeader("Accept-Language");49 case "HTTP_CONNECTION": return facesContext.getExternalContext().getRequest().getHeader("Connection");50 case "HTTP_COOKIE": return facesContext.getExternalContext().getRequest().getHeader("Cookie");51 case "HTTP_HOST": return facesContext.getExternalContext().getRequest().getHeader("Host");52 case "HTTP_REFERER": return facesContext.getExternalContext().getRequest().getHeader("Referer");53 case "HTTP_USER_AGENT": return facesContext.getExternalContext().getRequest().getHeader("User-Agent");54 }55 }56 57 // ==========================================58 // expose the public interface of this module59 // ==========================================60 return {61 get: _get62 }...
ContentModel.js
Source:ContentModel.js
1const sql = require("./ConnectMySQL");2const { GetUUID } = require('./AuthModel');3module.exports.GetByID = async (getRequest, result) => {4 sql.query(5 `SELECT tb_content.contentID, tb_content.contentText, tb_content.postID 6 FROM tb_content7 WHERE tb_content.contentID = ?`,8 [getRequest.contentID],9 (err, data) => {10 if (err) {11 result(err, null)12 } else {13 result(null, data);14 }15 }16 );17};18module.exports.GetByPost = async (getRequest, result) => {19 sql.query(20 `SELECT tb_content.contentID, tb_content.contentText, tb_content.postID 21 FROM tb_content22 WHERE tb_content.postID = ?`,23 [getRequest.postID],24 (err, data) => {25 if (err) {26 result(err, null)27 } else {28 data.forEach(item => {29 item.imageSource = process.env.BASE_URL + item.imageSource;30 })31 result(null, data);32 }33 }34 );35};36module.exports.Create = async (getRequest, result) => {37 const uuid = await GetUUID();38 sql.query(39 `INSERT INTO tb_content (tb_content.contentID, tb_content.contentText, tb_content.postID) VALUES (?, ?, ?)`,40 [uuid, getRequest.contentText, getRequest.postID],41 (err, data) => {42 if (err) {43 result(err, null)44 } else {45 result(null, { imageID: uuid, ...data });46 }47 }48 );49};50module.exports.UpdateByID = async (getRequest, result) => {51 sql.query(52 `UPDATE tb_content 53 SET tb_content.contentText = ?54 WHERE tb_content.contentID = ?`,55 [getRequest.contentText, getRequest.contentID],56 (err, data) => {57 if (err) {58 result(err, null)59 } else {60 result(null, { ...data });61 }62 }63 );64};65module.exports.DeleteByID = async (getRequest, result) => {66 sql.query(67 `DELETE FROM tb_content WHERE tb_content.contentID = ?`,68 [getRequest.contentID],69 (err, data) => {70 if (err) {71 result(err, null)72 } else {73 result(null, { ...data });74 }75 }76 );77};78module.exports.CreateContentPromise = async (getRequest) => {79 const uuid = await GetUUID();80 return new Promise((resolve, reject) => {81 sql.query(82 `INSERT INTO tb_content (tb_content.contentID, tb_content.contentText, tb_content.postID) VALUES (?, ?, ?)`,83 [uuid, getRequest.contentText, getRequest.postID],84 (err, data) => {85 if (err) {86 reject(new Error("Failed to upload content"));87 } else {88 resolve({ contentID: uuid, ...data });89 }90 }91 );92 })93};94module.exports.GetContentByPostPromise = async (getRequest) => {95 return new Promise((resolve, reject) => {96 sql.query(97 `SELECT tb_content.contentID, tb_content.contentText98 FROM tb_content99 WHERE tb_content.postID = ?`,100 [getRequest.postID],101 (err, data) => {102 if (err) {103 reject(new Error("Failed to get content"));104 } else {105 resolve(data);106 }107 }108 );109 })...
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.getLocations(function(err, data) {4 if (err) return console.error(err);5 console.dir(data);6});7var wpt = new WebPageTest('www.webpagetest.org');8#### getLocations(callback)9wpt.getLocations(function(err, data) {10 if (err) return console.error(err);11 console.dir(data);12});13#### getTests(callback)14wpt.getTests(function(err, data) {15 if (err) return console.error(err);16 console.dir(data);17});18#### getTestResults(testId, callback)19wpt.getTestResults('140627_4Q_1e9d9f4b4a1b1f4f8d4d4a4c4f4b4e4d', function(err, data) {20 if (err) return console.error(err);21 console.dir(data);22});23#### getTestStatus(testId, callback)24wpt.getTestStatus('140627_4Q_1e9d9f4b4a1b1f4f8d4d4a4c4f4b4e4d', function(err, data) {25 if (err) return console.error(err);26 console.dir(data);27});28#### runTest(url, options, callback)29var options = {30};
Using AI Code Generation
1var wpt = require('wpt.js');2var wpt = new WebPageTest('www.webpagetest.org');3wpt.getLocations(function(err, data) {4 if (err) {5 console.log('Error: '+err);6 } else {7 console.log(JSON.stringify(data));8 }9});10var wpt = require('wpt.js');11var wpt = new WebPageTest('www.webpagetest.org');12var options = {location: 'Dulles:Chrome'};13wpt.runTest(url, options, function(err, data) {14 if (err) {15 console.log('Error: '+err);16 } else {17 console.log(JSON.stringify(data));18 }19});20var wpt = require('wpt.js');21var wpt = new WebPageTest('www.webpagetest.org');22var testId = '140809_9X_1F8';23wpt.getTestResults(testId, function(err, data) {24 if (err) {25 console.log('Error: '+err);26 } else {27 console.log(JSON.stringify(data));28 }29});30var wpt = require('wpt.js');31var wpt = new WebPageTest('www.webpagetest.org');32var testId = '140809_9X_1F8';33wpt.getTestStatus(testId, function(err, data) {34 if (err) {35 console.log('Error: '+err);36 } else {37 console.log(JSON.stringify(data));38 }39});40var wpt = require('wpt.js');41var wpt = new WebPageTest('www.webpagetest.org');42var testId = '140809_9X_1F8';43wpt.getTestRequests(testId, function(err, data) {44 if (err) {
Using AI Code Generation
1var wpt = require('webpagetest');2var webpagetest = new wpt('www.webpagetest.org', 'A.5b6a1f7a9f9b5c7e4c4b1e7f0c6d4a7f');3webpagetest.runTest(url, function(err, data) {4 if(err) {5 console.log(err);6 } else {7 console.log(data);8 }9});
Using AI Code Generation
1var wpt = require('wpt');2var wpt = new WebPageTest('www.webpagetest.org', 'A.7b6f2f2f0c2a51e0a7b2d9b9a7b0c0d8');3var options = {4};5wpt.runTest(options, function(err, data) {6 if (err) return console.error(err);7 console.log(data);8});9var wpt = require('wpt');10var wpt = new WebPageTest('www.webpagetest.org', 'A.7b6f2f2f0c2a51e0a7b2d9b9a7b0c0d8');11var options = {12};13wpt.getTestResults(options, function(err, data) {14 if (err) return console.error(err);15 console.log(data);16});17var wpt = require('wpt');18var wpt = new WebPageTest('www.webpagetest.org', 'A.7b6f2f2f0c2a51e0a7b2d9b9a7b0c0d8');19wpt.getLocations(function(err, data) {20 if (err) return console.error(err);21 console.log(data);22});23var wpt = require('wpt');24var wpt = new WebPageTest('www.webpagetest.org', 'A.7b6f2f2f0c2a51e0a7b2d9b9a7b0c0d8');25wpt.getTesters(function(err, data) {26 if (err) return console.error(err);27 console.log(data);
Using AI Code Generation
1const wpt = require('wpt-api');2const wptApi = new wpt('A.0c0a7a9c9f9b7f2c2a2e7a4c2d2b7e4c');3 .then((data) => {4 console.log(data);5 })6 .catch((err) => {7 console.log(err);8 });9const wpt = require('wpt-api');10const wptApi = new wpt('A.0c0a7a9c9f9b7f2c2a2e7a4c2d2b7e4c');11 .then((data) => {12 console.log(data);13 })14 .catch((err) => {15 console.log(err);16 });17const wpt = require('wpt-api');18const wptApi = new wpt('A.0c0a7a9c9f9b7f2c2a2e7a4c2d2b7e4c');19wptApi.getTestResults('180124_8E_1ebf4c0e9e0f9b9e2c7b2a2c7b7d8d8c')20 .then((data) => {21 console.log(data);22 })23 .catch((err) => {24 console.log(err);25 });26const wpt = require('wpt-api');27const wptApi = new wpt('A.0c0a7a9c9f9b7f2c2a2e7a4c2d2b7e4c');28wptApi.getTestStatus('180124_8E_1ebf4c0e9e0f9b9e2c7b2a2c7b7d8d8c')29 .then((data) => {30 console.log(data);31 })
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!