From bb75597982a46be4925c0bf22be0cab015f0ddc1 Mon Sep 17 00:00:00 2001 From: jpntc Date: Sun, 10 Nov 2024 22:37:50 -0500 Subject: [PATCH] finish all tests --- config/config.json | 17 ++++----- learn-sequelize.js | 87 ++++++++++++++++++++++++++++++++++++++-------- models/index.js | 7 +++- package-lock.json | 27 ++++++++------ 4 files changed, 103 insertions(+), 35 deletions(-) diff --git a/config/config.json b/config/config.json index ef14e1e..c421bd9 100644 --- a/config/config.json +++ b/config/config.json @@ -6,12 +6,13 @@ "host": "127.0.0.1", "dialect": "postgres" }, - "test": { - "username": "ctp_user", - "password": "ctp_pass", - "database": "learn_sequelize", - "host": "127.0.0.1", - "dialect": "postgres", - "logging": false - } + "test": { + "use_env_variable": "DATABASE_URL", + "dialect": "postgres", + "dialectOptions": { + "ssl": { + "rejectUnauthorized": false + } + } + } } diff --git a/learn-sequelize.js b/learn-sequelize.js index d4b688f..a8fdaae 100644 --- a/learn-sequelize.js +++ b/learn-sequelize.js @@ -6,8 +6,16 @@ const { Genre, Movie, Actor } = require("./models"); - add one more Genre of your choice - duplicate entries are not allowed (try it to learn about errors) */ -function insertNewGenre() { - // Add code here +async function insertNewGenre() { + try { + // Adding a new genre + await Genre.create({ + id: 4, + name: 'SciFi', + }); + }catch(e){ + console.log("Error creating genre", e) + } } /* @@ -16,36 +24,73 @@ function insertNewGenre() { - add one more Movie of your choice. - the movie CANNOT be from year 2008 (try it to learn about errors) */ -function insertNewMovie() { - // Add code here +async function insertNewMovie() { + await Movie.create({ + id: 6, + title: 'Blue Beetle', + year: 2023 + }) + } /* Write a function that returns the title of the movie with ID=2 */ -function getMovieWithId2() { - // Add code here +async function getMovieWithId2() { + const movieWithId2 = await Movie.findAll({ + where:{ + id: 2 + } + }) + return movieWithId2[0].title; + } /* Write a function that returns an array of all the actor names */ -function getAllActors() { - // Add code here +async function getAllActors() { + const actors = await Actor.findAll(); + + const actorNames = [] + + for(let i = 0; i < actors.length; i++){ + actorNames.push(actors[i].name) + } + + + + return actorNames; } /* Write a function that returns an array of all the movie titles from 2008 */ -function getAllMoviesFrom2008() { - // Add code here +async function getAllMoviesFrom2008() { + + const moviesFrom2008 = await Movie.findAll({ + where:{ year: 2008} + }) + + + const movieNamesFrom2008 = []; + + for(let i = 0; i =8" @@ -1768,10 +1769,11 @@ } }, "node_modules/fill-range": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", - "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", "dev": true, + "license": "MIT", "dependencies": { "to-regex-range": "^5.0.1" }, @@ -2024,6 +2026,7 @@ "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", "dev": true, + "license": "MIT", "engines": { "node": ">=0.12.0" } @@ -2896,12 +2899,13 @@ "dev": true }, "node_modules/micromatch": { - "version": "4.0.5", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", - "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz", + "integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==", "dev": true, + "license": "MIT", "dependencies": { - "braces": "^3.0.2", + "braces": "^3.0.3", "picomatch": "^2.3.1" }, "engines": { @@ -3735,6 +3739,7 @@ "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", "dev": true, + "license": "MIT", "dependencies": { "is-number": "^7.0.0" },