diff --git a/README.md b/README.md index a2a277a..993ca91 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ Api similar to [dummy-api](https://dummyapi.io/docs) Api for playing around with dummy data. Feel free to use it in your demo projects, tutorials, or testing tasks. +All authorization headers are optional. + documentation: swagger url: diff --git a/package.json b/package.json index 54fcd24..b5e836f 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "@nestjs/platform-express": "^8.0.0", "@nestjs/swagger": "^5.2.1", "@prisma/client": "^3.12.0", + "axios": "^0.26.1", "bcryptjs": "^2.4.3", "compression": "^1.7.4", "dayjs": "^1.11.1", diff --git a/prisma/migrations/20220422024338_create_quote/migration.sql b/prisma/migrations/20220422024338_create_quote/migration.sql new file mode 100644 index 0000000..97048fe --- /dev/null +++ b/prisma/migrations/20220422024338_create_quote/migration.sql @@ -0,0 +1,26 @@ +-- CreateTable +CREATE TABLE "quote" ( + "id" UUID NOT NULL, + "content" TEXT, + "author" TEXT, + "tags" TEXT[], + "created_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updated_at" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + + CONSTRAINT "quote_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE INDEX "index_quote_on_created_at" ON "quote"("created_at"); + +-- CreateIndex +CREATE INDEX "index_quote_on_content" ON "quote"("content"); + +-- CreateIndex +CREATE INDEX "index_quote_on_author" ON "quote"("author"); + +-- CreateIndex +CREATE INDEX "index_quote_on_tags" ON "quote"("tags"); + +-- CreateIndex +CREATE INDEX "index_quote_on_updated_at" ON "quote"("updated_at"); diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 3fd008a..4d4705c 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -131,6 +131,21 @@ model todo { @@index([users_id], map: "index_todo_on_users_id") } +model quote { + id String @id @default(uuid()) @db.Uuid + content String? + author String? + tags String[] + created_at DateTime @default(now()) + updated_at DateTime @default(now()) + + @@index([created_at], map: "index_quote_on_created_at") + @@index([content], map: "index_quote_on_content") + @@index([author], map: "index_quote_on_author") + @@index([tags], map: "index_quote_on_tags") + @@index([updated_at], map: "index_quote_on_updated_at") +} + enum Title { mr ms diff --git a/prisma/seed.ts b/prisma/seed.ts index 8bb63ae..6ff288f 100644 --- a/prisma/seed.ts +++ b/prisma/seed.ts @@ -2,6 +2,7 @@ import { PrismaClient } from '@prisma/client'; import _ from 'lodash'; import { faker } from '@faker-js/faker'; import bcrypt from 'bcryptjs'; +import axios from 'axios'; const prisma = new PrismaClient(); @@ -12,6 +13,7 @@ const prisma = new PrismaClient(); await createTags(); await createComments(); await createTodos(); + await createQuotes(); })(); async function createUsers() { @@ -166,3 +168,28 @@ async function createTodos() { }); } } + +async function createQuotes() { + const rootUrl = `https://api.quotable.io`; + const response = await axios.get(`${rootUrl}/quotes`, { + params: { limit: 100 }, + }); + if (response) { + const responseData = response.data; + console.log('responseData = ', responseData); + + if (responseData) { + const resultsList = responseData.results; + for (let index = 0; index < resultsList.length; index++) { + const item = resultsList[index]; + await prisma.quote.create({ + data: { + content: item.content, + author: item.author, + tags: item.tags, + }, + }); + } + } + } +} diff --git a/yarn.lock b/yarn.lock index b28d875..b3f1301 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1428,7 +1428,7 @@ asynckit@^0.4.0: resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" integrity sha1-x57Zf380y48robyXkLzDZkdLS3k= -axios@0.26.1: +axios@0.26.1, axios@^0.26.1: version "0.26.1" resolved "https://registry.yarnpkg.com/axios/-/axios-0.26.1.tgz#1ede41c51fcf51bbbd6fd43669caaa4f0495aaa9" integrity sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==