Best JavaScript code snippet using ladle
20220513195551-likes.js
Source:20220513195551-likes.js
1'use strict';2module.exports = {3 up: (queryInterface, Sequelize) => {4 return queryInterface.bulkInsert('Likes', [5 {6 userId: 2,7 storyId: 1,8 createdAt: new Date(),9 updatedAt: new Date()10 },11 {12 userId: 2,13 storyId: 2,14 createdAt: new Date(),15 updatedAt: new Date()16 },17 {18 userId: 2,19 storyId: 3,20 createdAt: new Date(),21 updatedAt: new Date()22 },23 {24 userId: 2,25 storyId: 4,26 createdAt: new Date(),27 updatedAt: new Date()28 },29 {30 userId: 2,31 storyId: 5,32 createdAt: new Date(),33 updatedAt: new Date()34 },35 {36 userId: 3,37 storyId: 1,38 createdAt: new Date(),39 updatedAt: new Date()40 },41 {42 userId: 3,43 storyId: 2,44 createdAt: new Date(),45 updatedAt: new Date()46 },47 {48 userId: 3,49 storyId: 3,50 createdAt: new Date(),51 updatedAt: new Date()52 },53 {54 userId: 3,55 storyId: 4,56 createdAt: new Date(),57 updatedAt: new Date()58 },59 {60 userId: 3,61 storyId: 5,62 createdAt: new Date(),63 updatedAt: new Date()64 },65 {66 userId: 4,67 storyId: 1,68 createdAt: new Date(),69 updatedAt: new Date()70 },71 {72 userId: 4,73 storyId: 2,74 createdAt: new Date(),75 updatedAt: new Date()76 },77 {78 userId: 4,79 storyId: 3,80 createdAt: new Date(),81 updatedAt: new Date()82 },83 {84 userId: 4,85 storyId: 4,86 createdAt: new Date(),87 updatedAt: new Date()88 },89 {90 userId: 4,91 storyId: 5,92 createdAt: new Date(),93 updatedAt: new Date()94 },95 {96 userId: 5,97 storyId: 1,98 createdAt: new Date(),99 updatedAt: new Date()100 },101 {102 userId: 5,103 storyId: 2,104 createdAt: new Date(),105 updatedAt: new Date()106 },107 {108 userId: 5,109 storyId: 3,110 createdAt: new Date(),111 updatedAt: new Date()112 },113 {114 userId: 5,115 storyId: 4,116 createdAt: new Date(),117 updatedAt: new Date()118 },119 {120 userId: 5,121 storyId: 5,122 createdAt: new Date(),123 updatedAt: new Date()124 },125 {126 userId: 6,127 storyId: 2,128 createdAt: new Date(),129 updatedAt: new Date()130 },131 {132 userId: 6,133 storyId: 3,134 createdAt: new Date(),135 updatedAt: new Date()136 },137 {138 userId: 6,139 storyId: 4,140 createdAt: new Date(),141 updatedAt: new Date()142 },143 {144 userId: 6,145 storyId: 5,146 createdAt: new Date(),147 updatedAt: new Date()148 },149 {150 userId: 7,151 storyId: 2,152 createdAt: new Date(),153 updatedAt: new Date()154 },155 {156 userId: 7,157 storyId: 3,158 createdAt: new Date(),159 updatedAt: new Date()160 },161 {162 userId: 7,163 storyId: 4,164 createdAt: new Date(),165 updatedAt: new Date()166 },167 {168 userId: 7,169 storyId: 5,170 createdAt: new Date(),171 updatedAt: new Date()172 },173 {174 userId: 8,175 storyId: 2,176 createdAt: new Date(),177 updatedAt: new Date()178 },179 {180 userId: 8,181 storyId: 3,182 createdAt: new Date(),183 updatedAt: new Date()184 },185 {186 userId: 8,187 storyId: 4,188 createdAt: new Date(),189 updatedAt: new Date()190 },191 {192 userId: 8,193 storyId: 5,194 createdAt: new Date(),195 updatedAt: new Date()196 },197 {198 userId: 9,199 storyId: 2,200 createdAt: new Date(),201 updatedAt: new Date()202 },203 {204 userId: 9,205 storyId: 3,206 createdAt: new Date(),207 updatedAt: new Date()208 },209 {210 userId: 9,211 storyId: 4,212 createdAt: new Date(),213 updatedAt: new Date()214 },215 {216 userId: 9,217 storyId: 5,218 createdAt: new Date(),219 updatedAt: new Date()220 },221 {222 userId: 10,223 storyId: 3,224 createdAt: new Date(),225 updatedAt: new Date()226 },227 {228 userId: 10,229 storyId: 4,230 createdAt: new Date(),231 updatedAt: new Date()232 },233 {234 userId: 10,235 storyId: 5,236 createdAt: new Date(),237 updatedAt: new Date()238 },239 {240 userId: 10,241 storyId: 1,242 createdAt: new Date(),243 updatedAt: new Date()244 },245 {246 userId: 11,247 storyId: 3,248 createdAt: new Date(),249 updatedAt: new Date()250 },251 {252 userId: 11,253 storyId: 4,254 createdAt: new Date(),255 updatedAt: new Date()256 },257 {258 userId: 11,259 storyId: 5,260 createdAt: new Date(),261 updatedAt: new Date()262 },263 {264 userId: 12,265 storyId: 3,266 createdAt: new Date(),267 updatedAt: new Date()268 },269 {270 userId: 12,271 storyId: 4,272 createdAt: new Date(),273 updatedAt: new Date()274 },275 {276 userId: 12,277 storyId: 5,278 createdAt: new Date(),279 updatedAt: new Date()280 },281 {282 userId: 13,283 storyId: 3,284 createdAt: new Date(),285 updatedAt: new Date()286 },287 {288 userId: 13,289 storyId: 4,290 createdAt: new Date(),291 updatedAt: new Date()292 },293 {294 userId: 13,295 storyId: 5,296 createdAt: new Date(),297 updatedAt: new Date()298 },299 {300 userId: 14,301 storyId: 3,302 createdAt: new Date(),303 updatedAt: new Date()304 },305 {306 userId: 14,307 storyId: 4,308 createdAt: new Date(),309 updatedAt: new Date()310 },311 {312 userId: 14,313 storyId: 5,314 createdAt: new Date(),315 updatedAt: new Date()316 },317 {318 userId: 15,319 storyId: 3,320 createdAt: new Date(),321 updatedAt: new Date()322 },323 {324 userId: 15,325 storyId: 2,326 createdAt: new Date(),327 updatedAt: new Date()328 },329 {330 userId: 16,331 storyId: 1,332 createdAt: new Date(),333 updatedAt: new Date()334 },335 {336 userId: 16,337 storyId: 3,338 createdAt: new Date(),339 updatedAt: new Date()340 },341 {342 userId: 16,343 storyId: 4,344 createdAt: new Date(),345 updatedAt: new Date()346 },347 {348 userId: 17,349 storyId: 3,350 createdAt: new Date(),351 updatedAt: new Date()352 },353 {354 userId: 17,355 storyId: 5,356 createdAt: new Date(),357 updatedAt: new Date()358 },359 {360 userId: 18,361 storyId: 3,362 createdAt: new Date(),363 updatedAt: new Date()364 },365 {366 userId: 18,367 storyId: 2,368 createdAt: new Date(),369 updatedAt: new Date()370 },371 {372 userId: 19,373 storyId: 3,374 createdAt: new Date(),375 updatedAt: new Date()376 },377 {378 userId: 19,379 storyId: 4,380 createdAt: new Date(),381 updatedAt: new Date()382 },383 {384 userId: 20,385 storyId: 3,386 createdAt: new Date(),387 updatedAt: new Date()388 },389 {390 userId: 20,391 storyId: 1,392 createdAt: new Date(),393 updatedAt: new Date()394 },395 {396 userId: 21,397 storyId: 3,398 createdAt: new Date(),399 updatedAt: new Date()400 },401 {402 userId: 21,403 storyId: 1,404 createdAt: new Date(),405 updatedAt: new Date()406 },407 {408 userId: 21,409 storyId: 10,410 createdAt: new Date(),411 updatedAt: new Date()412 },413 {414 userId: 21,415 storyId: 9,416 createdAt: new Date(),417 updatedAt: new Date()418 },419 {420 userId: 21,421 storyId: 8,422 createdAt: new Date(),423 updatedAt: new Date()424 },425 {426 userId: 21,427 storyId: 7,428 createdAt: new Date(),429 updatedAt: new Date()430 },431 {432 userId: 21,433 storyId: 6,434 createdAt: new Date(),435 updatedAt: new Date()436 },437 {438 userId: 20,439 storyId: 10,440 createdAt: new Date(),441 updatedAt: new Date()442 },443 {444 userId: 20,445 storyId: 9,446 createdAt: new Date(),447 updatedAt: new Date()448 },449 {450 userId: 20,451 storyId: 8,452 createdAt: new Date(),453 updatedAt: new Date()454 },455 {456 userId: 20,457 storyId: 7,458 createdAt: new Date(),459 updatedAt: new Date()460 },461 {462 userId: 20,463 storyId: 6,464 createdAt: new Date(),465 updatedAt: new Date()466 },467 {468 userId: 19,469 storyId: 10,470 createdAt: new Date(),471 updatedAt: new Date()472 },473 {474 userId: 19,475 storyId: 9,476 createdAt: new Date(),477 updatedAt: new Date()478 },479 {480 userId: 19,481 storyId: 8,482 createdAt: new Date(),483 updatedAt: new Date()484 },485 {486 userId: 19,487 storyId: 7,488 createdAt: new Date(),489 updatedAt: new Date()490 },491 {492 userId: 19,493 storyId: 6,494 createdAt: new Date(),495 updatedAt: new Date()496 },497 {498 userId: 18,499 storyId: 10,500 createdAt: new Date(),501 updatedAt: new Date()502 },503 {504 userId: 18,505 storyId: 9,506 createdAt: new Date(),507 updatedAt: new Date()508 },509 {510 userId: 18,511 storyId: 7,512 createdAt: new Date(),513 updatedAt: new Date()514 },515 {516 userId: 18,517 storyId: 8,518 createdAt: new Date(),519 updatedAt: new Date()520 },521 {522 userId: 18,523 storyId: 6,524 createdAt: new Date(),525 updatedAt: new Date()526 },527 {528 userId: 17,529 storyId: 10,530 createdAt: new Date(),531 updatedAt: new Date()532 },533 {534 userId: 17,535 storyId: 8,536 createdAt: new Date(),537 updatedAt: new Date()538 },539 {540 userId: 17,541 storyId: 7,542 createdAt: new Date(),543 updatedAt: new Date()544 },545 {546 userId: 17,547 storyId: 6,548 createdAt: new Date(),549 updatedAt: new Date()550 },551 {552 userId: 17,553 storyId: 9,554 createdAt: new Date(),555 updatedAt: new Date()556 },557 {558 userId: 16,559 storyId: 9,560 createdAt: new Date(),561 updatedAt: new Date()562 },563 {564 userId: 16,565 storyId: 10,566 createdAt: new Date(),567 updatedAt: new Date()568 },569 {570 userId: 16,571 storyId: 8,572 createdAt: new Date(),573 updatedAt: new Date()574 },575 {576 userId: 16,577 storyId: 7,578 createdAt: new Date(),579 updatedAt: new Date()580 },581 {582 userId: 16,583 storyId: 6,584 createdAt: new Date(),585 updatedAt: new Date()586 },587 {588 userId: 15,589 storyId: 8,590 createdAt: new Date(),591 updatedAt: new Date()592 },593 {594 userId: 15,595 storyId: 10,596 createdAt: new Date(),597 updatedAt: new Date()598 },599 {600 userId: 15,601 storyId: 9,602 createdAt: new Date(),603 updatedAt: new Date()604 },605 {606 userId: 15,607 storyId: 7,608 createdAt: new Date(),609 updatedAt: new Date()610 },611 {612 userId: 15,613 storyId: 6,614 createdAt: new Date(),615 updatedAt: new Date()616 },617 {618 userId: 14,619 storyId: 8,620 createdAt: new Date(),621 updatedAt: new Date()622 },623 {624 userId: 14,625 storyId: 7,626 createdAt: new Date(),627 updatedAt: new Date()628 },629 {630 userId: 14,631 storyId: 6,632 createdAt: new Date(),633 updatedAt: new Date()634 },635 {636 userId: 14,637 storyId: 9,638 createdAt: new Date(),639 updatedAt: new Date()640 },641 {642 userId: 14,643 storyId: 10,644 createdAt: new Date(),645 updatedAt: new Date()646 },647 {648 userId: 13,649 storyId: 10,650 createdAt: new Date(),651 updatedAt: new Date()652 },653 {654 userId: 12,655 storyId: 10,656 createdAt: new Date(),657 updatedAt: new Date()658 },659 {660 userId: 12,661 storyId: 9,662 createdAt: new Date(),663 updatedAt: new Date()664 },665 {666 userId: 13,667 storyId: 8,668 createdAt: new Date(),669 updatedAt: new Date()670 },671 {672 userId: 11,673 storyId: 10,674 createdAt: new Date(),675 updatedAt: new Date()676 }677 ], {});678 },679 down: (queryInterface, Sequelize) => {680 return queryInterface.bulkDelete('Likes', null, {});681 }...
models.js
Source:models.js
1"use strict";2const BASE_URL = "https://hack-or-snooze-v3.herokuapp.com";3/******************************************************************************4 * Story: a single story in the system5 */6class Story {7 /** Make instance of Story from data object about story:8 * - {title, author, url, username, storyId, createdAt}9 */10 constructor({ storyId, title, author, url, username, createdAt }) {11 this.storyId = storyId;12 this.title = title;13 this.author = author;14 this.url = url;15 this.username = username;16 this.createdAt = createdAt;17 }18 /** Parses hostname out of URL and returns it. */19 getHostName() {20 // UNIMPLEMENTED: complete this function!21 return new URL(this.url).host;22 }23}24/******************************************************************************25 * List of Story instances: used by UI to show story lists in DOM.26 */27class StoryList {28 constructor(stories) {29 this.stories = stories;30 }31 /** Generate a new StoryList. It:32 *33 * - calls the API34 * - builds an array of Story instances35 * - makes a single StoryList instance out of that36 * - returns the StoryList instance.37 */38 static async getStories() {39 // Note presence of `static` keyword: this indicates that getStories is40 // **not** an instance method. Rather, it is a method that is called on the41 // class directly. Why doesn't it make sense for getStories to be an42 // instance method?43 // query the /stories endpoint (no auth required)44 const response = await axios({45 url: `${BASE_URL}/stories`,46 method: "GET",47 });48 // turn plain old story objects from API into instances of Story class49 const stories = response.data.stories.map(story => new Story(story));50 // build an instance of our own class using the new array of stories51 return new StoryList(stories);52 }53 /** Adds story data to API, makes a Story instance, adds it to story list.54 * - user - the current instance of User who will post the story55 * - obj of {title, author, url}56 *57 * Returns the new Story instance58 */59 async addStory(user, { title, author, url }) {60 const token = user.loginToken;61 const response = await axios({62 method: "POST",63 url: `${BASE_URL}/stories`,64 data: { token, story: { title, author, url } },65 });66 const story = new Story(response.data.story);67 this.stories.unshift(story);68 user.ownStories.unshift(story);69 return story;70 }71 72 //ToDo:73 async editStory(user, { storyId, title, author, url }) {74 const token = user.loginToken;75 //alert("storyId " + storyId + " title " + title + "author " + author + " url " + url);76 try{77 const response = await axios({78 method: "PATCH",79 url: `${BASE_URL}/stories/${storyId}`,80 data: { token, story: { title, author, url } },81 });82 } catch(error){83 alert("Error in update " + error);84 }85 //Update StoryList86 let response;87 try{88 response = await axios({89 url: `${BASE_URL}/stories/${storyId}`,90 method: "GET",91 });92 } catch(error){93 alert(error);94 }95 96 // turn plain old story objects from API into instances of Story class97 //const stories = response.story.map(storyItem => new Story(storyItem));98 let content = response.data;99 storyId = content.story.storyId;100 author = content.story.author;101 url = content.story.url;102 let username = content.story.username;103 let createdAt = content.story.createdAt;104 let updatedStory = new Story({storyId, title, author, url, username, createdAt});105 106 // filter out the story we are updating first remove the story107 this.stories = this.stories.filter(story => story.storyId !== storyId);108 this.stories.push(updatedStory);109 // do the same thing for the user's list of stories & their favorites110 user.ownStories = user.ownStories.filter(s => s.storyId !== storyId);111 user.ownStories.push(updatedStory);112 if( user.favorites.some(s => (s.storyId === storyId))){113 user.favorites = user.favorites.filter(s => s.storyId !== storyId);114 user.favorites.push(updatedStory);115 }116 }117 /** Delete story from API and remove from the story lists.118 *119 * - user: the current User instance120 * - storyId: the ID of the story you want to remove121 */122 async removeStory(user, storyId) {123 const token = user.loginToken;124 await axios({125 url: `${BASE_URL}/stories/${storyId}`,126 method: "DELETE",127 data: { token: user.loginToken }128 });129 // filter out the story whose ID we are removing130 this.stories = this.stories.filter(story => story.storyId !== storyId);131 // do the same thing for the user's list of stories & their favorites132 user.ownStories = user.ownStories.filter(s => s.storyId !== storyId);133 user.favorites = user.favorites.filter(s => s.storyId !== storyId);134 }135}//StoryList136/******************************************************************************137 * User: a user in the system (only used to represent the current user)138 */139class User {140 /** Make user instance from obj of user data and a token:141 * - {username, name, createdAt, favorites[], ownStories[]}142 * - token143 */144 constructor({145 username,146 name,147 createdAt,148 favorites = [],149 ownStories = []150 },151 token) {152 this.username = username;153 this.name = name;154 this.createdAt = createdAt;155 // instantiate Story instances for the user's favorites and ownStories156 this.favorites = favorites.map(s => new Story(s));157 this.ownStories = ownStories.map(s => new Story(s));158 // store the login token on the user so it's easy to find for API calls.159 this.loginToken = token;160 }161 /** Register new user in API, make User instance & return it.162 *163 * - username: a new username164 * - password: a new password165 * - name: the user's full name166 */167 static async signup(username, password, name) {168 const response = await axios({169 url: `${BASE_URL}/signup`,170 method: "POST",171 data: { user: { username, password, name } },172 });173 let { user } = response.data174 return new User(175 {176 username: user.username,177 name: user.name,178 createdAt: user.createdAt,179 favorites: user.favorites,180 ownStories: user.stories181 },182 response.data.token183 );184 }185 /** Login in user with API, make User instance & return it.186 * - username: an existing user's username187 * - password: an existing user's password188 */189 static async login(username, password) {190 const response = await axios({191 url: `${BASE_URL}/login`,192 method: "POST",193 data: { user: { username, password } },194 });195 let { user } = response.data;196 return new User(197 {198 username: user.username,199 name: user.name,200 createdAt: user.createdAt,201 favorites: user.favorites,202 ownStories: user.stories203 },204 response.data.token205 );206 }207 /** ChangeProfile in user with API, make User instance & return it.208 * - username: an existing user's username209 * - password: an existing user's password210 */211 static async changeUserProfile(password) {212 const username = currentUser.username;213 const token = currentUser.loginToken;214 215 console.log("c_username " + username);216 console.log("token " + token );217 console.log("new password" + password);218 let updated = false219 try{220 let response = await axios({221 method: "PATCH",222 url: `${BASE_URL}/users/${username}`,223 data: { token, user: { username, password } },224 });225 let content = response.data;226 let testUser = content.user.username;227 let tUser = content.user.name;228 updated = true;229 //alert("after update " + testUser);230 231 } catch(error){232 alert("Error in update " + error);233 }234 return updated;235 236 }237 /** When we already have credentials (token & username) for a user,238 * we can log them in automatically. This function does that.239 */240 static async loginViaStoredCredentials(token, username) {241 try {242 const response = await axios({243 url: `${BASE_URL}/users/${username}`,244 method: "GET",245 params: { token },246 });247 let { user } = response.data;248 return new User(249 {250 username: user.username,251 name: user.name,252 createdAt: user.createdAt,253 favorites: user.favorites,254 ownStories: user.stories255 },256 token257 );258 } catch (err) {259 console.error("loginViaStoredCredentials failed", err);260 return null;261 }262 }263 /** Add a story to the list of user favorites and update the API264 * - story: a Story instance to add to favorites265 */266 async addFavorite(story) {267 this.favorites.push(story);268 await this._addOrRemoveFavorite("add", story)269 }270 /** Remove a story to the list of user favorites and update the API271 * - story: the Story instance to remove from favorites272 */273 async removeFavorite(story) {274 this.favorites = this.favorites.filter(s => s.storyId !== story.storyId);275 await this._addOrRemoveFavorite("remove", story);276 }277 /** Update API with favorite/not-favorite.278 * - newState: "add" or "remove"279 * - story: Story instance to make favorite / not favorite280 * */281 async _addOrRemoveFavorite(newState, story) {282 const method = newState === "add" ? "POST" : "DELETE";283 const token = this.loginToken;284 await axios({285 url: `${BASE_URL}/users/${this.username}/favorites/${story.storyId}`,286 method: method,287 data: { token },288 });289 }290 /** Return true/false if given Story instance is a favorite of this user. */291 isFavorite(story) {292 return this.favorites.some(s => (s.storyId === story.storyId));293 }...
ratings.js
Source:ratings.js
1function loadRatingData(localRating) {2 var lastRatingUpdate = localStorage.getItem('lastRatingUpdate');3 if (lastRatingUpdate !== undefined) {4 if (localRating.rating_date <= lastRatingUpdate ) {5 addRatingToResults(localRating);6 return;7 }8 }9 var input = JSON.stringify(localRating);10 ajaxRequest('/rating_data', input, "application/json", "POST");11}12function getAverageRating(storyId) {13 var total = 0;14 var ratingCounter = 0;15 var localRatings = JSON.parse(localStorage.getItem('ratings'));16 for (var ratingItem in localRatings) {17 if (localRatings.hasOwnProperty(ratingItem)) {18 var ratingObject = localRatings[ratingItem];19 if (ratingObject.story_id === storyId) {20 ratingCounter += 1;21 total += ratingObject.vote;22 }23 }24 }25 var average = total/ratingCounter;26 if (isNaN(average)) average= 0;27 return average;28}29function handleRatingChange(n, storyId) {30 storyId = storyId.id;31 var username = document.cookie.split("=")[1]32 var ratingDate = Date.now();33 var ratingItem = {rating_id: storyId + username ,34 story_id: storyId, username: username,35 vote: n, rating_date: ratingDate}36 var ratingList = JSON.parse(localStorage.getItem('ratings'));37 if (ratingList == null) ratingList = [];38 ratingList.push(ratingItem);39 // find any duplicates40 var previousRating = ratingList.find(function (item) {41 return item.story_id === storyId &&42 item.username === username &&43 item.rating_date !== ratingDate;44 });45 // delete the previous rating from ratingList46 if (ratingList.indexOf(previousRating) > -1){47 ratingList.splice(ratingList.indexOf(previousRating), 1)48 }49 // delete rating50 if (ratingItem.vote === 0) {51 ratingList = ratingList.filter(function(elem) {52 return elem.rating_id !== ratingItem.rating_id;53 });54 }55 localStorage.setItem('ratings', JSON.stringify(ratingList));56 // store it in local storage57 storeRatingData(ratingItem);58 $('#'+"averageRating"+storyId).text("Average Rating: " + getAverageRating(storyId));59 addRatingToResults(ratingItem);60 ratingItem.vote_date = ratingItem.rating_date;61 delete ratingItem.rating_date;62 ajaxRequest('/rating_data', JSON.stringify(ratingItem), 'application/json', "POST" )63}64function addRatingToResults(ratingObject) {65 var storyId = ratingObject.story_id;66 var n = ratingObject.vote;67 var undoRatingButton = $('#' + "undoRatingButton" + storyId);68 var storyCard = $('#' + storyId);69 if (ratingObject.vote === 0) {70 undoRatingButton.hide()71 for (var k = 0; k<5; k++) {72 storyCard.find($('#' + 'star' + (k+1) + storyId)).attr('class', 'fa fa-star-o')73 }74 return;75 }76 undoRatingButton.show();77 // change UI of stars78 for (var i = 0; i <= n; i++) {79 var storyStar = storyCard.find($('#' + 'star' + (i) + storyId))80 storyStar.attr('class', 'fa fa-star')81 }82 for (var j = n; j < 5; j++) {83 var nextStoryStar = storyCard.find($('#' + 'star' + (j+1) + storyId))84 nextStoryStar.attr("class", 'fa fa-star-o');85 }86}87if (document.cookie) {88 socket.on('refreshRatings', function (ratingInput) {89 var ratingObj = JSON.parse(JSON.parse(ratingInput));90 ratingObj.rating_id = ratingObj.story_id + ratingObj.username91 delete ratingObj._id;92 var ratingDate = (new Date(ratingObj.vote_date).getTime());93 console.log(ratingDate);94 ratingObj.rating_date = ratingDate;95 delete ratingObj.vote_date;96 console.log("Rating input obj:", ratingObj);97 var ratingList = JSON.parse(localStorage.getItem('ratings'));98 if (ratingList == null) ratingList = [];99 // find any duplicates100 var previousRating = ratingList.find(function (item) {101 return item.rating_id === ratingObj.rating_id;102 });103 // delete the previous rating from ratingList104 if (ratingList.indexOf(previousRating) > -1) {105 ratingList.splice(ratingList.indexOf(previousRating), 1)106 }107 ratingList.push(ratingObj);108 // delete rating109 if (ratingObj.vote === 0) {110 ratingList = ratingList.filter(function (elem) {111 return elem.rating_id !== ratingObj.rating_id;112 });113 }114 localStorage.setItem('ratings', JSON.stringify(ratingList));115 // store it in local storage116 storeRatingData(ratingObj);117 $('#' + "averageRating" + ratingObj.story_id).text("Average Rating: " + getAverageRating(ratingObj.story_id));118 var loggedInUser = document.cookie.split("=")[1]119 if (loggedInUser === ratingObj.username) {120 addRatingToResults(ratingObj);121 }122 })...
20220512163056-comments.js
Source:20220512163056-comments.js
1'use strict';2module.exports = {3 up: (queryInterface, Sequelize) => {4 return queryInterface.bulkInsert('Comments', [5 {6 content: 'Great Review!',7 userId: 2,8 storyId: 1,9 createdAt: new Date(),10 updatedAt: new Date()11 },12 {13 content: "I'll take notes",14 userId: 3,15 storyId: 1,16 createdAt: new Date(),17 updatedAt: new Date()18 },19 {20 content: 'I like marvel better but nice review',21 userId: 3,22 storyId: 2,23 createdAt: new Date(),24 updatedAt: new Date()25 },26 {27 content: 'Best movie ever',28 userId: 3,29 storyId: 3,30 createdAt: new Date(),31 updatedAt: new Date()32 },33 {34 content: 'That movie was a masterpiece',35 userId: 4,36 storyId: 5,37 createdAt: new Date(),38 updatedAt: new Date()39 },40 {41 content: "I'm not a big fan of this movie",42 userId: 5,43 storyId: 5,44 createdAt: new Date(),45 updatedAt: new Date()46 },47 {48 content: 'They should make more movies like this one',49 userId: 4,50 storyId: 2,51 createdAt: new Date(),52 updatedAt: new Date()53 },54 {55 content: 'Not just a great movie but they also had a great actor',56 userId: 5,57 storyId: 4,58 createdAt: new Date(),59 updatedAt: new Date()60 },61 {62 content: 'Nicolas Cage is overrated',63 userId: 2,64 storyId: 4,65 createdAt: new Date(),66 updatedAt: new Date()67 },68 {69 content: 'Appealing work you have here.',70 userId: 11,71 storyId: 6,72 createdAt: new Date(),73 updatedAt: new Date()74 },75 {76 content: 'Just exquisite!',77 userId: 12,78 storyId: 7,79 createdAt: new Date(),80 updatedAt: new Date()81 },82 {83 content: `I think I'm crying. It's that nice.`,84 userId: 13,85 storyId: 7,86 createdAt: new Date(),87 updatedAt: new Date()88 },89 {90 content: 'Outstandingly simple illustration.',91 userId: 14,92 storyId: 7,93 createdAt: new Date(),94 updatedAt: new Date()95 },96 {97 content: 'This is appealing work, friend.',98 userId: 15,99 storyId: 8,100 createdAt: new Date(),101 updatedAt: new Date()102 },103 {104 content: 'So fabulous and neat!!',105 userId: 16,106 storyId: 8,107 createdAt: new Date(),108 updatedAt: new Date()109 },110 {111 content: 'Really thought out! Yes yes yes yes yes yes.',112 userId: 17,113 storyId: 9,114 createdAt: new Date(),115 updatedAt: new Date()116 },117 {118 content: 'Nice work you have here.',119 userId: 18,120 storyId: 10,121 createdAt: new Date(),122 updatedAt: new Date()123 },124 {125 content: 'This review has navigated straight to my heart',126 userId: 19,127 storyId: 10,128 createdAt: new Date(),129 updatedAt: new Date()130 },131 {132 content: 'Whoa.',133 userId: 20,134 storyId: 10,135 createdAt: new Date(),136 updatedAt: new Date()137 }138 ], {});139 },140 down: (queryInterface, Sequelize) => {141 return queryInterface.bulkDelete('Comments', null, {});142 }...
20211214180809-likeSeeds.js
Source:20211214180809-likeSeeds.js
1"use strict";2module.exports = {3 up: (queryInterface, Sequelize) => {4 return queryInterface.bulkInsert(5 "Likes",6 [7 {8 storyId: 1,9 commentId: null,10 userId: 11,11 createdAt: new Date(),12 updatedAt: new Date(),13 },14 {15 storyId: 2,16 commentId: null,17 userId: 11,18 createdAt: new Date(),19 updatedAt: new Date(),20 },21 {22 storyId: 4,23 commentId: null,24 userId: 11,25 createdAt: new Date(),26 updatedAt: new Date(),27 },28 {29 storyId: 3,30 commentId: null,31 userId: 11,32 createdAt: new Date(),33 updatedAt: new Date(),34 },35 {36 storyId: 5,37 commentId: null,38 userId: 11,39 createdAt: new Date(),40 updatedAt: new Date(),41 },42 {43 storyId: 5,44 commentId: null,45 userId: 2,46 createdAt: new Date(),47 updatedAt: new Date(),48 },49 {50 storyId: 5,51 commentId: null,52 userId: 3,53 createdAt: new Date(),54 updatedAt: new Date(),55 },56 {57 storyId: 5,58 commentId: null,59 userId: 4,60 createdAt: new Date(),61 updatedAt: new Date(),62 },63 {64 storyId: 3,65 commentId: null,66 userId: 5,67 createdAt: new Date(),68 updatedAt: new Date(),69 },70 {71 storyId: 3,72 commentId: null,73 userId: 4,74 createdAt: new Date(),75 updatedAt: new Date(),76 },77 {78 storyId: 2,79 commentId: null,80 userId: 3,81 createdAt: new Date(),82 updatedAt: new Date(),83 },84 ],85 {}86 );87 },88 down: (queryInterface, Sequelize) => {89 return queryInterface.bulkDelete("Likes", null, {});90 },...
Using AI Code Generation
1var ladle = require('ladle');2var storyId = ladle.storyId();3console.log(storyId);4var ladle = require('ladle');5var storyId = ladle.storyId();6console.log(storyId);7var ladle = require('ladle');8var storyId = ladle.storyId();9console.log(storyId);10var ladle = require('ladle');11var storyId = ladle.storyId();12console.log(storyId);13var ladle = require('ladle');14var storyId = ladle.storyId();15console.log(storyId);16var ladle = require('ladle');17var storyId = ladle.storyId();18console.log(storyId);19var ladle = require('ladle');20var storyId = ladle.storyId();21console.log(storyId);22var ladle = require('ladle');23var storyId = ladle.storyId();24console.log(storyId);25var ladle = require('ladle');26var storyId = ladle.storyId();27console.log(storyId);28var ladle = require('ladle');29var storyId = ladle.storyId();30console.log(storyId);31var ladle = require('ladle');32var storyId = ladle.storyId();33console.log(storyId);34var ladle = require('ladle');35var storyId = ladle.storyId();36console.log(storyId);
Using AI Code Generation
1var ladle = require('ladle');2var storyId = ladle.storyId;3var story = storyId('myStoryId');4story.then(function (data) {5 console.log(data);6});7var ladle = require('ladle');8var story = ladle.story('myStory');9story.then(function (data) {10 console.log(data);11});12var ladle = require('ladle');13var story = ladle.story('myStory', {start: '2015-01-01', end: '2015-01-02'});14story.then(function (data) {15 console.log(data);16});17var ladle = require('ladle');18var story = ladle.story('myStory', {start: '2015-01-01', end: '2015-01-02', page: 1});19story.then(function (data) {20 console.log(data);21});22var ladle = require('ladle');23var story = ladle.story('myStory', {start: '2015-01-01', end: '2015-01-02', page: 1, per_page: 1});24story.then(function (data) {25 console.log(data);26});27var ladle = require('ladle');28var story = ladle.story('myStory', {start: '2015-01-01', end: '2015-01-02', page: 1, per_page: 1, sort: 'asc'});29story.then(function (data) {30 console.log(data);31});32var ladle = require('ladle');33var story = ladle.story('myStory', {start: '2015-01-01', end: '2015-01-02', page: 1, per_page: 1, sort: 'asc', fields: 'title'});34story.then(function (data) {35 console.log(data);36});
Using AI Code Generation
1var ladle = require('ladle');2var storyId = ladle.storyId('path/to/story.json');3console.log(storyId);4{5 {6 }7}8var ladle = require('ladle');9var story = ladle.story('path/to/story.json');10console.log(story);11var ladle = require('ladle');12var story = ladle.story({13 labels: [ { name: 'Label Name', id: 1234567890 } ]14});15console.log(story);16var ladle = require('ladle');17var story = ladle.story({18 labels: [ { name: 'Label Name', id: 1234567890 } ]19});20console.log(story.id);21console.log(story.name);22console.log(story.description);23console.log(story.labels);24var ladle = require('ladle');25var story = ladle.story({26 labels: [ { name: 'Label Name', id: 1234567890 }
Using AI Code Generation
1var ladle = require('ladle');2var storyId = ladle.storyId();3var story = ladle.story(storyId);4console.log(story);5var ladle = require('ladle');6var storyId = ladle.storyId();7var story = ladle.story(storyId);8console.log(story);9var ladle = require('ladle');10var storyId = ladle.storyId();11var story = ladle.story(storyId);12console.log(story);13var ladle = require('ladle');14var storyId = ladle.storyId();15var story = ladle.story(storyId);16console.log(story);
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!!