├── .editorconfig
├── .env.example
├── .eslintignore
├── .eslintrc.js
├── .github
└── FUNDING.yml
├── .gitignore
├── .husky
├── commit-msg
└── pre-commit
├── .npmrc
├── .prettierignore
├── .prettierrc
├── .vscode
├── extensions.json
└── settings.json
├── README.md
├── app.vue
├── components
├── CreatePost.vue
├── Modal.vue
└── Post.vue
├── layouts
└── MainLayout.vue
├── notes.txt
├── nuxt.config.ts
├── package-lock.json
├── package.json
├── pages
├── auth.vue
└── index.vue
├── prisma
├── migrations
│ ├── 20230717195134_init
│ │ └── migration.sql
│ ├── 20230718064039_init
│ │ └── migration.sql
│ ├── 20230718120608_init
│ │ └── migration.sql
│ └── migration_lock.toml
└── schema.prisma
├── public
├── favicon.ico
├── github-logo.png
├── pwa-192x192.png
├── pwa-512x512.png
└── threads-logo.png
├── server
├── api
│ ├── create-post.js
│ ├── delete-post
│ │ └── [id].js
│ ├── get-all-posts.js
│ ├── like-post.js
│ └── unlike-post
│ │ └── [id].js
└── tsconfig.json
├── stores
└── user.js
└── tsconfig.json
/.editorconfig:
--------------------------------------------------------------------------------
1 | # Editor configuration, see http://editorconfig.org
2 | root = true
3 |
4 | [*]
5 | charset = utf-8
6 | end_of_line = lf
7 | indent_size = 2
8 | indent_style = space
9 | insert_final_newline = true
10 | trim_trailing_whitespace = true
11 |
12 | [*.md]
13 | max_line_length = off
14 | trim_trailing_whitespace = false
15 |
--------------------------------------------------------------------------------
/.env.example:
--------------------------------------------------------------------------------
1 | SUPABASE_URL=""
2 | SUPABASE_KEY=""
3 |
4 | BUCKET_URL=""
5 | # This was inserted by `prisma init`:
6 | # Environment variables declared in this file are automatically made available to Prisma.
7 | # See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema
8 |
9 | # Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
10 | # See the documentation for all the connection string options: https://pris.ly/d/connection-strings
11 |
12 | DATABASE_URL=""
--------------------------------------------------------------------------------
/.eslintignore:
--------------------------------------------------------------------------------
1 | .vscode/
2 |
3 | node_modules/
4 |
5 | # Build products
6 | build/
7 |
8 | vite.config.js
9 | .eslintrc.js
10 |
--------------------------------------------------------------------------------
/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | env: {
3 | browser: true,
4 | es2021: true,
5 | },
6 | extends: [
7 | 'plugin:vue/vue3-recommended',
8 | 'plugin:import/recommended',
9 | 'plugin:promise/recommended',
10 | 'plugin:sonarjs/recommended',
11 | ],
12 | parser: 'vue-eslint-parser',
13 | parserOptions: {
14 | ecmaVersion: 13,
15 | sourceType: 'module',
16 | },
17 | plugins: ['vue'],
18 | ignorePatterns: ['node_modules', 'dist', '*.d.ts'],
19 | rules: {
20 | 'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
21 | 'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
22 | 'vue/require-default-prop': 'off',
23 | // indentation (Already present in TypeScript)
24 | indent: ['error', 2],
25 |
26 | // Enforce trailing comma (Already present in TypeScript)
27 | 'comma-dangle': ['error', 'always-multiline'],
28 |
29 | // Enforce consistent spacing inside braces of object (Already present in TypeScript)
30 | 'object-curly-spacing': ['error', 'always'],
31 |
32 | // Disable max-len
33 | 'max-len': 'off',
34 |
35 | // we don't want it
36 | semi: 'off',
37 |
38 | 'no-unused-vars': 'off',
39 | 'no-undef': 'off',
40 |
41 | // Quote
42 | quotes: ['error', 'single'],
43 |
44 | // add parens only when required in arrow function
45 | 'arrow-parens': ['error', 'as-needed'],
46 |
47 | // add new line above comment
48 | 'newline-before-return': 'error',
49 |
50 | 'no-trailing-spaces': 'error',
51 |
52 | // add new line above comment
53 | 'lines-around-comment': [
54 | 'error',
55 | {
56 | beforeBlockComment: true,
57 | beforeLineComment: true,
58 | allowBlockStart: true,
59 | allowClassStart: true,
60 | allowObjectStart: true,
61 | allowArrayStart: true,
62 | },
63 | ],
64 |
65 | 'array-element-newline': ['error', 'consistent'],
66 | 'array-bracket-newline': ['error', 'consistent'],
67 |
68 | 'vue/multi-word-component-names': 'off',
69 | 'vue/no-setup-props-destructure': 'off',
70 | 'comma-dangle': 'off',
71 | 'arrow-parens': 'off',
72 | 'lines-around-comment': 'off',
73 | 'vue/html-self-closing': 'off',
74 | 'vue/html-closing-bracket-newline': 'off',
75 | 'vue/max-attributes-per-line': 'off',
76 | 'vue/max-attributes-per-line': 'off',
77 | 'vue/html-indent': 'off',
78 |
79 | 'padding-line-between-statements': [
80 | 'error',
81 | { blankLine: 'always', prev: 'expression', next: 'const' },
82 | { blankLine: 'always', prev: 'const', next: 'expression' },
83 | { blankLine: 'always', prev: 'multiline-const', next: '*' },
84 | { blankLine: 'always', prev: '*', next: 'multiline-const' },
85 | ],
86 |
87 | // Plugin: eslint-plugin-import
88 | 'import/prefer-default-export': 'off',
89 | 'import/newline-after-import': ['error', { count: 1 }],
90 |
91 | // ignore virtual files
92 | 'import/no-unresolved': [
93 | 2,
94 | {
95 | ignore: [
96 | '~pages$',
97 | 'virtual:generated-layouts',
98 |
99 | // Ignore vite's ?raw imports
100 | '.*?raw',
101 | ],
102 | },
103 | ],
104 |
105 | 'no-shadow': 'off',
106 |
107 | // ESLint plugin vue
108 | // 'vue/block-tag-newline': 'error',
109 | 'vue/component-api-style': 'error',
110 | 'vue/require-prop-types': 'off',
111 | 'vue/component-name-in-template-casing': [
112 | 'error',
113 | 'PascalCase',
114 | { registeredComponentsOnly: false },
115 | ],
116 | 'vue/custom-event-name-casing': [
117 | 'error',
118 | 'camelCase',
119 | {
120 | ignores: ['/^(click):[a-z]+((d)|([A-Z0-9][a-z0-9]+))*([A-Z])?/'],
121 | },
122 | ],
123 | 'vue/define-macros-order': 'error',
124 |
125 | 'vue/html-comment-content-newline': 'error',
126 | 'vue/html-comment-content-spacing': 'error',
127 | 'vue/html-comment-indent': 'error',
128 | // 'vue/html-indent': ['error', 2],
129 | 'vue/match-component-file-name': 'error',
130 | 'vue/no-child-content': 'error',
131 |
132 | // NOTE this rule only supported in SFC, Users of the unplugin-vue-define-options should disable that rule: https://github.com/vuejs/eslint-plugin-vue/issues/1886
133 | // 'vue/no-duplicate-attr-inheritance': 'error',
134 | 'vue/no-empty-component-block': 'error',
135 | 'vue/no-multiple-objects-in-class': 'error',
136 | 'vue/no-reserved-component-names': 'error',
137 | 'vue/no-template-target-blank': 'error',
138 | 'vue/no-useless-mustaches': 'error',
139 | 'vue/no-useless-v-bind': 'error',
140 | 'vue/padding-line-between-blocks': 'error',
141 | 'vue/prefer-separate-static-class': 'error',
142 | 'vue/prefer-true-attribute-shorthand': 'error',
143 | 'vue/v-on-function-call': 'error',
144 | },
145 | settings: {
146 | 'import/resolver': {
147 | node: {
148 | extensions: ['.js', '.mjs'],
149 | },
150 | },
151 | },
152 | };
153 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 | github: [fdhhhdjd]# Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
3 | patreon: user?u=65668237
4 | open_collective: # Replace with a single Open Collective username
5 | ko_fi: tientainguyen
6 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
7 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
8 | liberapay: # Replace with a single Liberapay username
9 | issuehunt: # Replace with a single IssueHunt username
10 | otechie: # Replace with a single Otechie username
11 | custom: ["https://profile-forme.cf"]
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Nuxt dev/build outputs
2 | .output
3 | .nuxt
4 | .nitro
5 | .cache
6 | dist
7 |
8 | # Node dependencies
9 | node_modules
10 |
11 | # Logs
12 | logs
13 | *.log
14 |
15 | # Misc
16 | .DS_Store
17 | .fleet
18 | .idea
19 |
20 | # Local env files
21 | .env
22 | .env.*
23 | !.env.example
24 |
--------------------------------------------------------------------------------
/.husky/commit-msg:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | . "$(dirname $0)/_/husky.sh"
3 |
4 | npx commitlint --edit $1
5 |
--------------------------------------------------------------------------------
/.husky/pre-commit:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 | . "$(dirname -- "$0")/_/husky.sh"
3 |
4 | npm run eslint
5 |
--------------------------------------------------------------------------------
/.npmrc:
--------------------------------------------------------------------------------
1 | shamefully-hoist=true
2 | strict-peer-dependencies=false
3 |
--------------------------------------------------------------------------------
/.prettierignore:
--------------------------------------------------------------------------------
1 | package.json
2 | package-lock.json
3 | public
4 | node_modules
5 | build
--------------------------------------------------------------------------------
/.prettierrc:
--------------------------------------------------------------------------------
1 | {
2 | "singleQuote": true,
3 | "endOfLine": "lf",
4 | "semi": true,
5 | "tabWidth": 2,
6 | "trailingComma": "es5",
7 | "printWidth": 100,
8 | "overrides": [
9 | {
10 | "files": "*.css",
11 | "options": {
12 | "singleQuote": false,
13 | "tabWidth": 4
14 | }
15 | }
16 | ]
17 | }
18 |
--------------------------------------------------------------------------------
/.vscode/extensions.json:
--------------------------------------------------------------------------------
1 | {
2 | "recommendations": ["Vue.volar", "Vue.vscode-typescript-vue-plugin"]
3 | }
4 |
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "vetur.validation.template": true,
3 | "vetur.format.defaultFormatter.html": "none",
4 | "editor.defaultFormatter": "esbenp.prettier-vscode",
5 | // Set the default
6 | "editor.formatOnSave": false,
7 | // Enable per-language
8 | "[javascript]": {
9 | "editor.formatOnSave": true
10 | },
11 | "[vue]": {
12 | "editor.formatOnSave": true
13 | },
14 | "cSpell.words": [
15 | "localstorage"
16 | ]
17 | }
18 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | ## Study With Me: Code Web Blog Simple NuxtJs
11 |
12 | ## Team Word: Liên hệ công việc https://profile-forme.cf
13 |
14 | ## 1. Nguyễn Tiến Tài ( Maintanin 🚩).
15 |
16 | ## Tài Khoản Donate li Cf 🥛,để có động lực code cho anh em tham khảo 😄😄.
17 |
18 | 
19 |
20 | ## Mk: NGUYEN TIEN TAI
21 |
22 | ## STK: 1651002972052
23 |
24 | ## Chi Nhánh: NGAN HANG TMCP AN BINH (ABBANK).
25 |
26 | ## SUPORT CONTACT: [https://profile-forme.cf](https://profile-forme.cf)
27 |
28 | ## Thank You <3.
--------------------------------------------------------------------------------
/app.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
19 |
20 |
32 |
33 |
34 |
35 |
39 |
--------------------------------------------------------------------------------
/components/CreatePost.vue:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
17 |
18 |
19 |
New Thread
20 |
21 |
22 |
26 |
27 |
28 |
29 |
33 |
34 | {{ user.identities[0].identity_data.full_name }}
35 |
36 |
37 |
38 |
39 |
44 |
47 |
48 |
56 |
57 |
58 |
59 |
60 |
61 |
65 |
66 |
67 |
68 |
73 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
96 | Post
97 |
98 |
99 | Please wait...
100 |
101 |
102 |
103 |
104 |
105 |
106 |
187 |
--------------------------------------------------------------------------------
/components/Modal.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 | Close Modal
9 |
10 |
11 |
12 |
13 | Log Out
14 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/components/Post.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
{{ post.name }}
8 |
9 |
13 |
18 |
19 |
20 |
21 |
22 |
23 |
27 | Delete
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
38 |
39 |
{{ post.text }}
40 |
45 |
46 |
47 |
52 |
58 |
64 |
65 |
66 |
67 | {{ post.likes.length }}
68 |
69 |
70 |
71 | likes
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
--------------------------------------------------------------------------------
/layouts/MainLayout.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
17 |
18 |
22 |
23 |
24 |
28 |
29 |
30 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/notes.txt:
--------------------------------------------------------------------------------
1 | CREATE PROJECT
2 | npx nuxi@latest init Blog-Simple-NuxtJs
3 |
4 | SUPABASE:
5 | project password: nguyentientai!
6 |
7 | PRISMA:
8 | npx prisma init
9 | npx prisma generate
10 | npx prisma migrate dev --name init
11 |
12 | NPM PACKAGES:
13 | npm i @nuxtjs/supabase @nuxtjs/tailwindcss @pinia/nuxt @prisma/client @vite-pwa/nuxt nuxt-icon prisma uuid
14 | npm i pinia -f
--------------------------------------------------------------------------------
/nuxt.config.ts:
--------------------------------------------------------------------------------
1 | // https://nuxt.com/docs/api/configuration/nuxt-config
2 | export default defineNuxtConfig({
3 | pages: true,
4 | modules: [
5 | 'nuxt-icon',
6 | '@nuxtjs/tailwindcss',
7 | '@nuxtjs/supabase',
8 | '@pinia/nuxt',
9 | "@vite-pwa/nuxt",
10 | ],
11 | runtimeConfig: {
12 | public: {
13 | bucketUrl: process.env.BUCKET_URL
14 | }
15 | },
16 | devtools: { enabled: false },
17 | pwa: {
18 | manifest: {
19 | name: "Threads Clone",
20 | short_name: "Threads Clone",
21 | description: "This is a Threads Clone",
22 | theme_color: "#000000",
23 | icons: [
24 | {
25 | src: "pwa-192x192.png",
26 | sizes: "192x192",
27 | type: "image/png",
28 | },
29 | {
30 | src: "pwa-512x512.png",
31 | sizes: "512x512",
32 | type: "image/png",
33 | },
34 | ],
35 | },
36 | devOptions: {
37 | enabled: true,
38 | type: "module",
39 | },
40 | },
41 | app: {
42 | head: {
43 | charset: 'utf-8',
44 | viewport: 'width=device-width, initial-scale=1, maximum-scale=1',
45 | }
46 | }
47 | })
48 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "Blog-Simple-NuxtJs",
3 | "private": true,
4 | "scripts": {
5 | "build": "nuxt build",
6 | "dev": "nuxt dev",
7 | "generate": "nuxt generate",
8 | "preview": "nuxt preview",
9 | "postinstall": "nuxt prepare",
10 | "pre-commit": "echo \"[Husky] pre-commit\""
11 | },
12 | "husky": {
13 | "hooks": {
14 | "pre-commit": "npx lint-staged"
15 | }
16 | },
17 | "commitlint": {
18 | "extends": [
19 | "@commitlint/config-conventional"
20 | ]
21 | },
22 | "devDependencies": {
23 | "@nuxt/devtools": "latest",
24 | "@types/node": "^18.16.19",
25 | "nuxt": "^3.6.3",
26 | "prisma": "^5.1.1",
27 | "@commitlint/cli": "^17.6.5",
28 | "@commitlint/config-conventional": "^17.6.5",
29 | "husky": "^8.0.0",
30 | "eslint": "^8.45.0",
31 | "eslint-plugin-import": "^2.28.0",
32 | "eslint-plugin-promise": "^6.1.1",
33 | "eslint-plugin-sonarjs": "^0.19.0",
34 | "eslint-plugin-vue": "^9.15.1",
35 | "prettier": "^3.0.0"
36 | },
37 | "dependencies": {
38 | "@nuxtjs/supabase": "^0.3.8",
39 | "@nuxtjs/tailwindcss": "^6.8.0",
40 | "@pinia/nuxt": "^0.4.11",
41 | "@prisma/client": "^5.1.1",
42 | "@vite-pwa/nuxt": "^0.1.0",
43 | "nuxt-icon": "^0.4.2",
44 | "pinia": "^2.1.4",
45 | "uuid": "^9.0.0"
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/pages/auth.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
Threads
7 |
8 |
9 |
10 |
11 |
Login / Register
12 |
13 |
28 |
29 |
30 | Github
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/pages/index.vue:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
10 |
11 |
12 |
13 |
14 |
15 |
Loading...
16 |
17 |
18 |
19 |
20 |
21 |
Make the first post!
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/prisma/migrations/20230717195134_init/migration.sql:
--------------------------------------------------------------------------------
1 | -- CreateTable
2 | CREATE TABLE "Posts" (
3 | "id" SERIAL NOT NULL,
4 | "userId" UUID NOT NULL,
5 | "name" TEXT NOT NULL,
6 | "image" TEXT NOT NULL,
7 | "text" TEXT NOT NULL,
8 | "picture" TEXT NOT NULL,
9 | "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
10 |
11 | CONSTRAINT "Posts_pkey" PRIMARY KEY ("id")
12 | );
13 |
--------------------------------------------------------------------------------
/prisma/migrations/20230718064039_init/migration.sql:
--------------------------------------------------------------------------------
1 | -- CreateTable
2 | CREATE TABLE "Likes" (
3 | "id" SERIAL NOT NULL,
4 | "userId" UUID NOT NULL,
5 | "postId" INTEGER NOT NULL,
6 | "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
7 |
8 | CONSTRAINT "Likes_pkey" PRIMARY KEY ("id")
9 | );
10 |
11 | -- AddForeignKey
12 | ALTER TABLE "Likes" ADD CONSTRAINT "Likes_postId_fkey" FOREIGN KEY ("postId") REFERENCES "Posts"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
13 |
--------------------------------------------------------------------------------
/prisma/migrations/20230718120608_init/migration.sql:
--------------------------------------------------------------------------------
1 | -- DropForeignKey
2 | ALTER TABLE "Likes" DROP CONSTRAINT "Likes_postId_fkey";
3 |
4 | -- AddForeignKey
5 | ALTER TABLE "Likes" ADD CONSTRAINT "Likes_postId_fkey" FOREIGN KEY ("postId") REFERENCES "Posts"("id") ON DELETE CASCADE ON UPDATE CASCADE;
6 |
--------------------------------------------------------------------------------
/prisma/migrations/migration_lock.toml:
--------------------------------------------------------------------------------
1 | # Please do not edit this file manually
2 | # It should be added in your version-control system (i.e. Git)
3 | provider = "postgresql"
--------------------------------------------------------------------------------
/prisma/schema.prisma:
--------------------------------------------------------------------------------
1 | // This is your Prisma schema file,
2 | // learn more about it in the docs: https://pris.ly/d/prisma-schema
3 |
4 | generator client {
5 | provider = "prisma-client-js"
6 | }
7 |
8 | datasource db {
9 | provider = "postgresql"
10 | url = env("DATABASE_URL")
11 | }
12 |
13 | model Posts {
14 | id Int @id @default(autoincrement())
15 | userId String @db.Uuid
16 | name String
17 | image String
18 | text String
19 | picture String
20 | createdAt DateTime @default(now())
21 | likes Likes[]
22 | }
23 |
24 | model Likes {
25 | id Int @id @default(autoincrement())
26 | userId String @db.Uuid
27 | postId Int
28 | createdAt DateTime @default(now())
29 | post Posts @relation(fields: [postId], references: [id], onDelete: Cascade)
30 | }
31 |
--------------------------------------------------------------------------------
/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fdhhhdjd/Web-Blog-Simple-NuxtJs/97defc576eede5aef7f02f853ada4117c5fed4fb/public/favicon.ico
--------------------------------------------------------------------------------
/public/github-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fdhhhdjd/Web-Blog-Simple-NuxtJs/97defc576eede5aef7f02f853ada4117c5fed4fb/public/github-logo.png
--------------------------------------------------------------------------------
/public/pwa-192x192.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fdhhhdjd/Web-Blog-Simple-NuxtJs/97defc576eede5aef7f02f853ada4117c5fed4fb/public/pwa-192x192.png
--------------------------------------------------------------------------------
/public/pwa-512x512.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fdhhhdjd/Web-Blog-Simple-NuxtJs/97defc576eede5aef7f02f853ada4117c5fed4fb/public/pwa-512x512.png
--------------------------------------------------------------------------------
/public/threads-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fdhhhdjd/Web-Blog-Simple-NuxtJs/97defc576eede5aef7f02f853ada4117c5fed4fb/public/threads-logo.png
--------------------------------------------------------------------------------
/server/api/create-post.js:
--------------------------------------------------------------------------------
1 | import { PrismaClient } from '@prisma/client'
2 | const prisma = new PrismaClient()
3 |
4 | export default defineEventHandler(async (event) => {
5 | const body = await readBody(event)
6 |
7 | console.log(body)
8 |
9 | const res = await prisma.posts.create({
10 | data: {
11 | userId: body.userId,
12 | name: body.name,
13 | image: body.image,
14 | text: body.text,
15 | picture: body.picture,
16 | }
17 | })
18 |
19 | return res
20 | })
--------------------------------------------------------------------------------
/server/api/delete-post/[id].js:
--------------------------------------------------------------------------------
1 | import { PrismaClient } from '@prisma/client'
2 | const prisma = new PrismaClient()
3 |
4 | export default defineEventHandler(async (event) => {
5 | const deleted = await prisma.posts.delete({
6 | where: { id: Number(event.context.params.id) },
7 | })
8 |
9 | return deleted
10 | })
--------------------------------------------------------------------------------
/server/api/get-all-posts.js:
--------------------------------------------------------------------------------
1 | import { PrismaClient } from '@prisma/client'
2 | const prisma = new PrismaClient()
3 |
4 | export default defineEventHandler(async (event) => {
5 | let posts = await prisma.posts.findMany({
6 | orderBy: { id: "desc" },
7 | include: { likes: true }
8 | })
9 | return posts
10 | })
--------------------------------------------------------------------------------
/server/api/like-post.js:
--------------------------------------------------------------------------------
1 | import { PrismaClient } from '@prisma/client'
2 | const prisma = new PrismaClient()
3 |
4 | export default defineEventHandler(async (event) => {
5 | const body = await readBody(event)
6 |
7 | const res = await prisma.likes.create({
8 | data: {
9 | userId: body.userId,
10 | postId: body.postId,
11 | }
12 | })
13 |
14 | return res
15 | })
--------------------------------------------------------------------------------
/server/api/unlike-post/[id].js:
--------------------------------------------------------------------------------
1 | import { PrismaClient } from '@prisma/client'
2 | const prisma = new PrismaClient()
3 |
4 | export default defineEventHandler(async (event) => {
5 | const deleted = await prisma.likes.delete({
6 | where: { id: Number(event.context.params.id) },
7 | })
8 |
9 | return deleted
10 | })
--------------------------------------------------------------------------------
/server/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "../.nuxt/tsconfig.server.json"
3 | }
4 |
--------------------------------------------------------------------------------
/stores/user.js:
--------------------------------------------------------------------------------
1 | // stores/counter.js
2 | import { defineStore } from "pinia";
3 |
4 | export const useUserStore = defineStore("user", {
5 | state: () => ({
6 | posts: [],
7 | isMenuOverlay: false,
8 | isLogoutOverlay: false,
9 | }),
10 |
11 | actions: {
12 | async getAllPosts() {
13 | let res = await useFetch("/api/get-all-posts");
14 | console.log(res, "data");
15 | this.posts = res.data;
16 | return res.data;
17 | },
18 | },
19 | });
20 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | // https://nuxt.com/docs/guide/concepts/typescript
3 | "extends": "./.nuxt/tsconfig.json"
4 | }
5 |
--------------------------------------------------------------------------------