├── 02-medium-course-selling-app-admin-dashboard
├── .eslintrc.cjs
├── .gitignore
├── README.md
├── index.html
├── package-lock.json
├── package.json
├── postcss.config.js
├── public
│ └── vite.svg
├── src
│ ├── App.css
│ ├── App.jsx
│ ├── assets
│ │ └── react.svg
│ ├── components
│ │ ├── CreateCourse.jsx
│ │ ├── ImageContainer.jsx
│ │ ├── Landing.jsx
│ │ ├── Login.jsx
│ │ ├── Navbar.jsx
│ │ ├── ShowCourses.jsx
│ │ ├── Signup.css
│ │ └── Signup.jsx
│ ├── index.css
│ ├── main.jsx
│ └── utils
│ │ └── constants.js
├── tailwind.config.js
├── vite.config.js
└── yarn.lock
├── CourseAppBackend
├── .gitignore
├── README.md
├── db
│ └── index.js
├── index.js
├── middleware
│ └── auth.js
├── package-lock.json
├── package.json
└── routes
│ ├── admin.js
│ └── user.js
├── JS_dataStructure
├── stack.js
└── toggleFunctionArguments.js
├── JsRefresher
├── TimeCounter.js
├── asyncCounters.js
├── callback.js
├── expenditure-analysis.js
├── pattern.js
├── promises.js
├── refresher.js
└── todolist.js
├── Prisma
├── .gitignore
├── package-lock.json
├── package.json
├── src
│ ├── 01-create-user.ts
│ ├── 02-crate-post.ts
│ ├── 03-create-user-and-post.ts
│ ├── 04-get-user.ts
│ ├── 05-get-post.ts
│ ├── 06-debug-logs.ts
│ ├── 07-update-user.ts
│ ├── 08-delete-unpublished-posts.ts
│ ├── advance-debug
│ │ └── debug.ts
│ └── filtering
│ │ ├── 01-ends-with.ts
│ │ └── 02-limits-and-offsets.ts
└── tsconfig.json
├── PrismaPRactice
├── .gitignore
├── dist
│ ├── 02-crate-post.js
│ └── create-user.js
├── package-lock.json
├── package.json
├── prisma
│ ├── migrations
│ │ ├── 20231004081953_init
│ │ │ └── migration.sql
│ │ └── migration_lock.toml
│ └── schema.prisma
├── src
│ ├── 02-crate-post.ts
│ └── create-user.ts
└── tsconfig.json
├── README.md
├── SQL
├── .gitignore
├── package-lock.json
├── package.json
├── src
│ ├── create-index.ts
│ ├── create-table.ts
│ ├── delete-data.ts
│ ├── get-data.ts
│ ├── insert-data.ts
│ ├── joins
│ │ ├── advance-1.ts
│ │ ├── advance-2.ts
│ │ ├── advance-3.ts
│ │ └── basic.ts
│ ├── update-data.ts
│ └── utils.ts
├── tsconfig.json
└── yarn.lock
├── Week4
└── index.js
├── node_modules
└── .package-lock.json
├── package-lock.json
├── package.json
├── week-10
├── .DS_Store
├── .gitignore
├── admin-client
│ ├── .DS_Store
│ ├── index.html
│ ├── package-lock.json
│ ├── package.json
│ ├── public
│ │ ├── class.jpeg
│ │ └── vite.svg
│ ├── src
│ │ ├── App.css
│ │ ├── App.jsx
│ │ ├── assets
│ │ │ └── react.svg
│ │ ├── components
│ │ │ ├── AddCourse.jsx
│ │ │ ├── Appbar.jsx
│ │ │ ├── Course.jsx
│ │ │ ├── Courses.jsx
│ │ │ ├── Landing.jsx
│ │ │ ├── Loading.jsx
│ │ │ ├── Signin.jsx
│ │ │ └── Signup.jsx
│ │ ├── config.js
│ │ ├── index.css
│ │ ├── main.jsx
│ │ ├── store
│ │ │ ├── atoms
│ │ │ │ ├── course.js
│ │ │ │ └── user.js
│ │ │ └── selectors
│ │ │ │ ├── course.js
│ │ │ │ ├── isUserLoading.js
│ │ │ │ └── userEmail.js
│ │ └── utils.js
│ └── vite.config.js
├── server
│ ├── .gitignore
│ ├── db
│ │ └── index.js
│ ├── index.js
│ ├── middleware
│ │ └── auth.js
│ ├── package-lock.json
│ ├── package.json
│ └── routes
│ │ ├── admin.js
│ │ └── user.js
└── yarn.lock
├── week-12-1
├── classes
│ └── node_modules
│ │ ├── .package-lock.json
│ │ ├── helpful-decorators
│ │ ├── LICENSE
│ │ ├── README.md
│ │ ├── dist-node
│ │ │ └── index.js
│ │ ├── dist-src
│ │ │ ├── bind.js
│ │ │ ├── debounce.js
│ │ │ ├── delay.js
│ │ │ ├── index.js
│ │ │ ├── measure.js
│ │ │ ├── memoize.js
│ │ │ ├── mixin.js
│ │ │ ├── once.js
│ │ │ ├── sortby.js
│ │ │ └── throttle.js
│ │ ├── dist-types
│ │ │ ├── bind.d.ts
│ │ │ ├── debounce.d.ts
│ │ │ ├── delay.d.ts
│ │ │ ├── index.d.ts
│ │ │ ├── measure.d.ts
│ │ │ ├── memoize.d.ts
│ │ │ ├── mixin.d.ts
│ │ │ ├── once.d.ts
│ │ │ ├── sortby.d.ts
│ │ │ └── throttle.d.ts
│ │ ├── dist-web
│ │ │ └── index.js
│ │ └── package.json
│ │ ├── lodash.debounce
│ │ ├── LICENSE
│ │ ├── README.md
│ │ ├── index.js
│ │ └── package.json
│ │ ├── lodash.delay
│ │ ├── LICENSE
│ │ ├── README.md
│ │ ├── index.js
│ │ └── package.json
│ │ ├── lodash.memoize
│ │ ├── LICENSE
│ │ ├── README.md
│ │ ├── index.js
│ │ └── package.json
│ │ ├── lodash.once
│ │ ├── LICENSE
│ │ ├── README.md
│ │ ├── index.js
│ │ └── package.json
│ │ └── lodash.throttle
│ │ ├── LICENSE
│ │ ├── README.md
│ │ ├── index.js
│ │ └── package.json
└── todo-backend
│ ├── .gitignore
│ ├── build
│ ├── build
│ │ ├── routes.js
│ │ └── swagger.json
│ ├── routes.ts
│ ├── src
│ │ ├── app.js
│ │ ├── server.js
│ │ └── todos
│ │ │ ├── todo.js
│ │ │ ├── todoService.js
│ │ │ └── todosController.js
│ └── swagger.json
│ ├── node-client
│ ├── core
│ │ ├── ApiError.ts
│ │ ├── ApiRequestOptions.ts
│ │ ├── ApiResult.ts
│ │ ├── CancelablePromise.ts
│ │ ├── OpenAPI.ts
│ │ └── request.ts
│ ├── index.ts
│ ├── models
│ │ └── Todo.ts
│ └── services
│ │ └── DefaultService.ts
│ ├── package-lock.json
│ ├── package.json
│ ├── src
│ ├── app.ts
│ ├── server.ts
│ └── todos
│ │ ├── todo.ts
│ │ ├── todoService.ts
│ │ └── todosController.ts
│ ├── tsconfig.json
│ ├── tsoa.json
│ └── yarn.lock
├── week-16-master
├── .idea
│ └── workspace.xml
├── part-1-create-simple-server
│ ├── client
│ │ ├── .gitignore
│ │ ├── index.ts
│ │ ├── package-lock.json
│ │ ├── package.json
│ │ ├── tsconfig.json
│ │ └── zeus
│ │ │ ├── const.ts
│ │ │ └── index.ts
│ ├── client2
│ │ ├── .gitignore
│ │ ├── client
│ │ │ └── zeus
│ │ │ │ ├── const.ts
│ │ │ │ └── index.ts
│ │ ├── package-lock.json
│ │ ├── package.json
│ │ └── tsconfig.json
│ └── server
│ │ ├── .gitignore
│ │ ├── package-lock.json
│ │ ├── package.json
│ │ ├── schema.gql
│ │ ├── src
│ │ ├── index.ts
│ │ └── schema.gql
│ │ └── tsconfig.json
├── part-2-hasura-dockerfile
│ ├── README.md
│ ├── docker-compose.yml
│ └── hasura
│ │ └── config.yaml
└── part-3-hasura-dockerfile
│ ├── README.md
│ ├── docker-compose.yml
│ └── hasura
│ └── config.yaml
├── week-16
└── week-16-master
│ ├── .idea
│ └── workspace.xml
│ ├── part-1-create-simple-server
│ ├── client
│ │ ├── .gitignore
│ │ ├── index.ts
│ │ ├── package.json
│ │ ├── tsconfig.json
│ │ └── zeus
│ │ │ ├── const.ts
│ │ │ └── index.ts
│ └── server
│ │ ├── .gitignore
│ │ ├── package-lock.json
│ │ ├── package.json
│ │ ├── schema.gql
│ │ ├── src
│ │ ├── index.ts
│ │ └── schema.gql
│ │ └── tsconfig.json
│ ├── part-2-hasura-dockerfile
│ ├── README.md
│ ├── docker-compose.yml
│ ├── hasura
│ │ └── config.yaml
│ └── package-lock.json
│ └── part-3-hasura-dockerfile
│ ├── README.md
│ ├── docker-compose.yml
│ ├── hasura
│ └── config.yaml
│ └── image.png
├── week-8-repo
├── TodoApp API.postman_collection.json
├── client
│ ├── .eslintrc.cjs
│ ├── .gitignore
│ ├── README.md
│ ├── index.html
│ ├── package-lock.json
│ ├── package.json
│ ├── public
│ │ └── vite.svg
│ ├── src
│ │ ├── App.css
│ │ ├── App.tsx
│ │ ├── Components
│ │ │ ├── Login.tsx
│ │ │ ├── Signup.tsx
│ │ │ └── TodoList.tsx
│ │ ├── assets
│ │ │ └── react.svg
│ │ ├── index.css
│ │ ├── main.tsx
│ │ ├── store
│ │ │ └── authState.ts
│ │ └── vite-env.d.ts
│ ├── tsconfig.json
│ ├── tsconfig.node.json
│ ├── vite.config.ts
│ └── yarn.lock
├── common
│ ├── .npmignore
│ ├── dist
│ │ ├── index.d.ts
│ │ └── index.js
│ ├── node_modules
│ │ ├── .package-lock.json
│ │ ├── @ajaydeep968
│ │ │ └── common
│ │ │ │ ├── dist
│ │ │ │ ├── index.d.ts
│ │ │ │ └── index.js
│ │ │ │ ├── package.json
│ │ │ │ └── tsconfig.json
│ │ └── zod
│ │ │ ├── LICENSE
│ │ │ ├── README.md
│ │ │ ├── index.d.ts
│ │ │ ├── lib
│ │ │ ├── ZodError.d.ts
│ │ │ ├── ZodError.js
│ │ │ ├── __tests__
│ │ │ │ ├── Mocker.d.ts
│ │ │ │ └── Mocker.js
│ │ │ ├── benchmarks
│ │ │ │ ├── discriminatedUnion.d.ts
│ │ │ │ ├── discriminatedUnion.js
│ │ │ │ ├── index.d.ts
│ │ │ │ ├── index.js
│ │ │ │ ├── object.d.ts
│ │ │ │ ├── object.js
│ │ │ │ ├── primitives.d.ts
│ │ │ │ ├── primitives.js
│ │ │ │ ├── realworld.d.ts
│ │ │ │ ├── realworld.js
│ │ │ │ ├── string.d.ts
│ │ │ │ ├── string.js
│ │ │ │ ├── union.d.ts
│ │ │ │ └── union.js
│ │ │ ├── errors.d.ts
│ │ │ ├── errors.js
│ │ │ ├── external.d.ts
│ │ │ ├── external.js
│ │ │ ├── helpers
│ │ │ │ ├── enumUtil.d.ts
│ │ │ │ ├── enumUtil.js
│ │ │ │ ├── errorUtil.d.ts
│ │ │ │ ├── errorUtil.js
│ │ │ │ ├── parseUtil.d.ts
│ │ │ │ ├── parseUtil.js
│ │ │ │ ├── partialUtil.d.ts
│ │ │ │ ├── partialUtil.js
│ │ │ │ ├── typeAliases.d.ts
│ │ │ │ ├── typeAliases.js
│ │ │ │ ├── util.d.ts
│ │ │ │ └── util.js
│ │ │ ├── index.d.ts
│ │ │ ├── index.js
│ │ │ ├── index.mjs
│ │ │ ├── index.umd.js
│ │ │ ├── locales
│ │ │ │ ├── en.d.ts
│ │ │ │ └── en.js
│ │ │ ├── types.d.ts
│ │ │ └── types.js
│ │ │ └── package.json
│ ├── package-lock.json
│ ├── package.json
│ ├── src
│ │ └── index.ts
│ └── tsconfig.json
└── server
│ ├── .gitignore
│ ├── README.md
│ ├── TodoApp API.postman_collection.json
│ ├── db
│ └── index.ts
│ ├── index.ts
│ ├── middleware
│ └── index.ts
│ ├── package-lock.json
│ ├── package.json
│ ├── routes
│ ├── auth.ts
│ └── todo.ts
│ └── tsconfig.json
├── week-8.1
├── .DS_Store
├── TodoApp API.postman_collection.json
├── client
│ ├── .eslintrc.cjs
│ ├── .gitignore
│ ├── README.md
│ ├── index.html
│ ├── package-lock.json
│ ├── package.json
│ ├── public
│ │ └── vite.svg
│ ├── src
│ │ ├── App.css
│ │ ├── App.tsx
│ │ ├── Components
│ │ │ ├── Login.tsx
│ │ │ ├── Signup.tsx
│ │ │ └── TodoList.tsx
│ │ ├── assets
│ │ │ └── react.svg
│ │ ├── index.css
│ │ ├── main.tsx
│ │ ├── store
│ │ │ └── authState.ts
│ │ └── vite-env.d.ts
│ ├── tsconfig.json
│ ├── tsconfig.node.json
│ ├── vite.config.ts
│ └── yarn.lock
├── common
│ ├── .DS_Store
│ ├── .npmignore
│ ├── dist
│ │ ├── index.d.ts
│ │ └── index.js
│ ├── node_modules
│ │ ├── .package-lock.json
│ │ └── zod
│ │ │ ├── LICENSE
│ │ │ ├── README.md
│ │ │ ├── index.d.ts
│ │ │ ├── lib
│ │ │ ├── ZodError.d.ts
│ │ │ ├── ZodError.js
│ │ │ ├── __tests__
│ │ │ │ ├── Mocker.d.ts
│ │ │ │ └── Mocker.js
│ │ │ ├── benchmarks
│ │ │ │ ├── discriminatedUnion.d.ts
│ │ │ │ ├── discriminatedUnion.js
│ │ │ │ ├── index.d.ts
│ │ │ │ ├── index.js
│ │ │ │ ├── object.d.ts
│ │ │ │ ├── object.js
│ │ │ │ ├── primitives.d.ts
│ │ │ │ ├── primitives.js
│ │ │ │ ├── realworld.d.ts
│ │ │ │ ├── realworld.js
│ │ │ │ ├── string.d.ts
│ │ │ │ ├── string.js
│ │ │ │ ├── union.d.ts
│ │ │ │ └── union.js
│ │ │ ├── errors.d.ts
│ │ │ ├── errors.js
│ │ │ ├── external.d.ts
│ │ │ ├── external.js
│ │ │ ├── helpers
│ │ │ │ ├── enumUtil.d.ts
│ │ │ │ ├── enumUtil.js
│ │ │ │ ├── errorUtil.d.ts
│ │ │ │ ├── errorUtil.js
│ │ │ │ ├── parseUtil.d.ts
│ │ │ │ ├── parseUtil.js
│ │ │ │ ├── partialUtil.d.ts
│ │ │ │ ├── partialUtil.js
│ │ │ │ ├── typeAliases.d.ts
│ │ │ │ ├── typeAliases.js
│ │ │ │ ├── util.d.ts
│ │ │ │ └── util.js
│ │ │ ├── index.d.ts
│ │ │ ├── index.js
│ │ │ ├── index.mjs
│ │ │ ├── index.umd.js
│ │ │ ├── locales
│ │ │ │ ├── en.d.ts
│ │ │ │ └── en.js
│ │ │ ├── types.d.ts
│ │ │ └── types.js
│ │ │ └── package.json
│ ├── package-lock.json
│ ├── package.json
│ ├── src
│ │ └── index.ts
│ └── tsconfig.json
├── package-lock.json
└── server
│ ├── .gitignore
│ ├── README.md
│ ├── TodoApp API.postman_collection.json
│ ├── db
│ └── index.ts
│ ├── index.ts
│ ├── middleware
│ └── index.ts
│ ├── package-lock.json
│ ├── package.json
│ ├── routes
│ ├── auth.ts
│ └── todo.ts
│ └── tsconfig.json
├── week-8
├── index.ts
└── tsconfig.json
├── week2
├── .gitignore
├── index.js
├── package-lock.json
├── package.json
└── rough.js
├── week3
├── .gitignore
├── package-lock.json
├── package.json
├── public
│ └── index.html
├── server.js
└── todos.json
├── week6
├── .gitignore
├── index.html
├── index.js
├── package-lock.json
└── package.json
└── week8.2
├── .gitignore
├── .npmrc
├── README.md
├── apps
├── docs
│ ├── .eslintrc.js
│ ├── .gitignore
│ ├── README.md
│ ├── app
│ │ ├── favicon.ico
│ │ ├── globals.css
│ │ ├── layout.tsx
│ │ ├── page.module.css
│ │ └── page.tsx
│ ├── next-env.d.ts
│ ├── next.config.js
│ ├── package.json
│ ├── public
│ │ ├── circles.svg
│ │ ├── next.svg
│ │ ├── turborepo.svg
│ │ └── vercel.svg
│ └── tsconfig.json
└── web
│ ├── .eslintrc.js
│ ├── .gitignore
│ ├── README.md
│ ├── app
│ ├── favicon.ico
│ ├── globals.css
│ ├── layout.tsx
│ ├── page.module.css
│ └── page.tsx
│ ├── next-env.d.ts
│ ├── next.config.js
│ ├── package.json
│ ├── public
│ ├── circles.svg
│ ├── next.svg
│ ├── turborepo.svg
│ └── vercel.svg
│ └── tsconfig.json
├── package-lock.json
├── package.json
├── packages
├── eslint-config-custom
│ ├── README.md
│ ├── library.js
│ ├── next.js
│ ├── package.json
│ └── react-internal.js
├── tsconfig
│ ├── base.json
│ ├── nextjs.json
│ ├── package.json
│ └── react-library.json
└── ui
│ ├── .eslintrc.js
│ ├── Signup.tsx
│ ├── card.tsx
│ ├── index.tsx
│ ├── package.json
│ ├── tsconfig.json
│ └── turbo
│ └── generators
│ ├── config.ts
│ └── templates
│ └── component.hbs
├── tsconfig.json
└── turbo.json
/02-medium-course-selling-app-admin-dashboard/.eslintrc.cjs:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | env: { browser: true, es2020: true },
3 | extends: [
4 | 'eslint:recommended',
5 | 'plugin:react/recommended',
6 | 'plugin:react/jsx-runtime',
7 | 'plugin:react-hooks/recommended',
8 | ],
9 | parserOptions: { ecmaVersion: 'latest', sourceType: 'module' },
10 | settings: { react: { version: '18.2' } },
11 | plugins: ['react-refresh'],
12 | rules: {
13 | 'react-refresh/only-export-components': 'warn',
14 | },
15 | }
16 |
--------------------------------------------------------------------------------
/02-medium-course-selling-app-admin-dashboard/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 | pnpm-debug.log*
8 | lerna-debug.log*
9 |
10 | node_modules
11 | dist
12 | dist-ssr
13 | *.local
14 |
15 | # Editor directories and files
16 | .vscode/*
17 | !.vscode/extensions.json
18 | .idea
19 | .DS_Store
20 | *.suo
21 | *.ntvs*
22 | *.njsproj
23 | *.sln
24 | *.sw?
25 |
--------------------------------------------------------------------------------
/02-medium-course-selling-app-admin-dashboard/README.md:
--------------------------------------------------------------------------------
1 |
2 | ### Create the frontend for the ADMIN DASHBOARD for a course selling app
3 |
4 | Please start backend from week-3/solutions/03-course-app-medium.js (add app.listen, cors if its not there already)
5 |
6 | 1. Start the backend from week-3/solutions/02-course-app-medium.js
7 | 2. We will use authentication, which means you need to get back the jwt and store it in localStorage (read https://www.robinwieruch.de/local-storage-react/)
8 | 3. You need to understand routing for this to work, so we've added a basic boilerplate that lets you navigate between 3 routes (check App.jsx)
9 | 4. To test the current app, run `npm run dev` and see the output on localhost:3000
10 |
11 | Things that will confuse you -
12 | 1. Routing. Here is a great blog post explaining it - https://hygraph.com/blog/routing-in-react . If you open App.jsx you should intuitively be able to understand whats happening
13 | 2. Authentication (More specifically , how to store it in localstorage and how to put it in headers when sending the request)
14 |
15 | ### Hard todo -
16 | Add routing to introduce a new route /courses/:id which shows you the contents of a single course
17 | It should also let you edit the course title, description and price
18 | This will be needed in the next assignment
--------------------------------------------------------------------------------
/02-medium-course-selling-app-admin-dashboard/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Vite + React
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/02-medium-course-selling-app-admin-dashboard/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "02-medium-course-selling-app",
3 | "private": true,
4 | "version": "0.0.0",
5 | "type": "module",
6 | "scripts": {
7 | "dev": "vite",
8 | "build": "vite build",
9 | "lint": "eslint src --ext js,jsx --report-unused-disable-directives --max-warnings 0",
10 | "preview": "vite preview"
11 | },
12 | "dependencies": {
13 | "axios": "^1.4.0",
14 | "react": "^18.2.0",
15 | "react-dom": "^18.2.0",
16 | "react-router-dom": "^6.14.1",
17 | "react-toastify": "^9.1.3",
18 | "vanilla-tilt": "^1.8.1"
19 | },
20 | "devDependencies": {
21 | "@types/react": "^18.0.37",
22 | "@types/react-dom": "^18.0.11",
23 | "@vitejs/plugin-react": "^4.0.0",
24 | "autoprefixer": "^10.4.14",
25 | "eslint": "^8.38.0",
26 | "eslint-plugin-react": "^7.32.2",
27 | "eslint-plugin-react-hooks": "^4.6.0",
28 | "eslint-plugin-react-refresh": "^0.3.4",
29 | "postcss": "^8.4.25",
30 | "tailwindcss": "^3.3.2",
31 | "vite": "^4.3.9"
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/02-medium-course-selling-app-admin-dashboard/postcss.config.js:
--------------------------------------------------------------------------------
1 | export default {
2 | plugins: {
3 | tailwindcss: {},
4 | autoprefixer: {},
5 | },
6 | }
7 |
--------------------------------------------------------------------------------
/02-medium-course-selling-app-admin-dashboard/public/vite.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/02-medium-course-selling-app-admin-dashboard/src/App.css:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ajaydeep123/100xdevsCohort/20b7c0ac5444177a23e8b3bf298adb3c3be87057/02-medium-course-selling-app-admin-dashboard/src/App.css
--------------------------------------------------------------------------------
/02-medium-course-selling-app-admin-dashboard/src/App.jsx:
--------------------------------------------------------------------------------
1 | import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
2 | import Login from './components/Login';
3 | import Landing from "./components/Landing";
4 | import CreateCourse from './components/CreateCourse';
5 | import Signup from './components/Signup';
6 | import ShowCourses from './components/ShowCourses';
7 |
8 | // This file shows how you can do routing in React.
9 | // Try going to /login, /register, /about, /courses on the website and see how the html changes
10 | // based on the route.
11 | // You can also try going to /random and see what happens (a route that doesnt exist)
12 | function App() {
13 | return (
14 |
15 |
16 | } />
17 | } />
18 | } />
19 | } />
20 | } />
21 |
22 |
23 | );
24 | }
25 |
26 | export default App;
--------------------------------------------------------------------------------
/02-medium-course-selling-app-admin-dashboard/src/components/CreateCourse.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | /// You need to add input boxes to take input for users to create a course.
3 | /// I've added one input so you understand the api to do it.
4 | function CreateCourse() {
5 | const [title, setTitle] = React.useState("");
6 |
7 | return
8 |
Create Course Page
9 | setTitle(e.target.value)} />
10 |
11 |
12 | }
13 | export default CreateCourse;
--------------------------------------------------------------------------------
/02-medium-course-selling-app-admin-dashboard/src/components/Navbar.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import {Link} from 'react-router-dom'
3 |
4 |
5 | const Navbar = ({currentpage,redirectToSignup, redirectToLogin }) => {
6 |
7 | const isSignupPage = currentpage === 'signup';
8 | const isLoginPage = currentpage === 'login';
9 | return (
10 |
11 |
12 |

17 |
18 |
#100xdevs
19 | {!isSignupPage && !isLoginPage && (
20 |
21 |
24 |
25 | )}
26 |
27 |
28 | );
29 | };
30 |
31 | export default Navbar;
--------------------------------------------------------------------------------
/02-medium-course-selling-app-admin-dashboard/src/components/ShowCourses.jsx:
--------------------------------------------------------------------------------
1 | import React from "react";
2 |
3 | function ShowCourses() {
4 | const [courses, setCourses] = React.useState([]);
5 |
6 | // Add code to fetch courses from the server
7 | // and set it in the courses state variable.
8 | return
9 |
Create Course Page
10 | {courses.map(c => )}
11 |
12 | }
13 |
14 | function Course(props) {
15 | return
16 |
{props.title}
17 |
18 | }
19 |
20 | export default ShowCourses;
--------------------------------------------------------------------------------
/02-medium-course-selling-app-admin-dashboard/src/components/Signup.css:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ajaydeep123/100xdevsCohort/20b7c0ac5444177a23e8b3bf298adb3c3be87057/02-medium-course-selling-app-admin-dashboard/src/components/Signup.css
--------------------------------------------------------------------------------
/02-medium-course-selling-app-admin-dashboard/src/index.css:
--------------------------------------------------------------------------------
1 | @import url('https://fonts.googleapis.com/css2?family=Bebas+Neue&display=swap');
2 | @import url('https://fonts.googleapis.com/css2?family=Great+Vibes&family=Noto+Serif+Devanagari&display=swap');
3 | @import url('https://fonts.googleapis.com/css2?family=Patua+One&display=swap');
4 | @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400&display=swap');
5 | @tailwind base;
6 | @tailwind components;
7 | @tailwind utilities;
--------------------------------------------------------------------------------
/02-medium-course-selling-app-admin-dashboard/src/main.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import ReactDOM from 'react-dom/client'
3 | import App from './App.jsx'
4 | import './index.css'
5 |
6 | ReactDOM.createRoot(document.getElementById('root')).render(
7 |
8 |
9 | ,
10 | )
11 |
--------------------------------------------------------------------------------
/02-medium-course-selling-app-admin-dashboard/src/utils/constants.js:
--------------------------------------------------------------------------------
1 | const API_URL = 'http://localhost:3000'
2 | export const API_ROUTES = {
3 | SIGN_UP: `${API_URL}/admin/signup`,
4 | LOG_IN: `${API_URL}/admin/login`,
5 | COURSES: `${API_URL}/admin/courses`,
6 | COURSE: `${API_URL}/admin/courses/:courseId`
7 | }
8 |
9 | export const APP_ROUTES = {
10 | SIGN_UP: '/signup',
11 | LOG_IN: '/login',
12 | LANDING_PAGE: '/',
13 | }
--------------------------------------------------------------------------------
/02-medium-course-selling-app-admin-dashboard/tailwind.config.js:
--------------------------------------------------------------------------------
1 | /** @type {import('tailwindcss').Config} */
2 | export default {
3 | content: [
4 | "./index.html",
5 | "./src/**/*.{js,ts,jsx,tsx}",
6 | ],
7 | theme: {
8 | extend: {
9 | colors:{
10 | 'powderwala':'#DEDCD3',
11 | 'acchaSafed':"#FAF9F6",
12 | 'acchaBlack':"#0E0E0D",
13 | },
14 | fontFamily:{
15 | 'headerWala':['Bebas Neue', 'sans-serif'],
16 | 'hindi': ['Noto Serif Devanagari','Great Vibes'],
17 | 'heroSection':['Patua One'],
18 | 'bodySection':['Poppins'],
19 | },
20 | },
21 | },
22 | plugins: [],
23 | }
--------------------------------------------------------------------------------
/02-medium-course-selling-app-admin-dashboard/vite.config.js:
--------------------------------------------------------------------------------
1 | import { defineConfig } from 'vite'
2 | import react from '@vitejs/plugin-react'
3 |
4 | // https://vitejs.dev/config/
5 | export default defineConfig({
6 | plugins: [react()],
7 | })
8 |
--------------------------------------------------------------------------------
/CourseAppBackend/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
--------------------------------------------------------------------------------
/CourseAppBackend/db/index.js:
--------------------------------------------------------------------------------
1 | const express = require('express');
2 | const mongoose = require('mongoose');
3 | const cors = require('cors');
4 | const adminRouter = require("./routes/admin");
5 | const userRouter = require("./routes/user");
6 |
7 | const app = express();
8 |
9 | app.use(cors());
10 | app.use(express.json());
11 |
12 | app.use("/admin", adminRouter)
13 | app.use("/user", userRouter)
14 |
15 |
16 | // Connect to MongoDB
17 | mongoose.connect('mongodb+srv://asrajay968:EDa684Vm9B1mjfLL@cluster0.7poatss.mongodb.net/', {
18 | useNewUrlParser: true,
19 | useUnifiedTopology: true,
20 | dbName: "courses"
21 | }).then(console.log(`Db connected successfully`))
22 | .catch(error => {
23 | console.log(`Db connection failed`);
24 | console.log(error);
25 | process.exit(1);
26 | });
27 |
28 |
29 | app.listen(3000, () => console.log('Server running on port 3000'));
--------------------------------------------------------------------------------
/CourseAppBackend/middleware/auth.js:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ajaydeep123/100xdevsCohort/20b7c0ac5444177a23e8b3bf298adb3c3be87057/CourseAppBackend/middleware/auth.js
--------------------------------------------------------------------------------
/CourseAppBackend/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "02-course-app-easy",
3 | "version": "1.0.0",
4 | "description": "### Description 1. Admins should be able to sign up 2. Admins should be able to create courses 1. Course has a title, description, price, and image link 2. Course should be able to be published or unpublished 3. Admins should be able to edit courses 4. Users should be able to sign up 5. Users should be able to purchase courses 6. Users should be able to view purchased courses 7. Users should be able to view all courses",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "keywords": [],
10 | "author": "",
11 | "license": "ISC",
12 | "dependencies": {
13 | "bcrypt": "^5.1.0",
14 | "express": "^4.18.2",
15 | "jsonwebtoken": "^9.0.1",
16 | "mongoose": "^7.3.1"
17 | },
18 | "devDependencies": {
19 | "nodemon": "^2.0.22"
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/JS_dataStructure/toggleFunctionArguments.js:
--------------------------------------------------------------------------------
1 | const toggle = (...args) =>{
2 | let index =0;
3 | return function(){
4 | if(args.length){
5 | console.log(args[index++]);
6 |
7 | //edge case
8 |
9 | if(index>=args.length){
10 | index =0;
11 | }
12 | }
13 | }
14 | }
15 |
16 | const hello = toggle("1", "2", "3");
17 | hello();
18 | hello();
--------------------------------------------------------------------------------
/JsRefresher/TimeCounter.js:
--------------------------------------------------------------------------------
1 | function timer(currentTime){
2 | const interval = setInterval(increment, 1000);
3 | function increment(){
4 | currentTime.setSeconds(currentTime.getSeconds()+1);
5 | console.clear();
6 | console.log(currentTime);
7 | }
8 | return interval;
9 | }
10 |
11 | const currentTime = new Date();
12 |
13 | timer(currentTime);
14 |
15 | // clearInterval(timer(currentTime));
--------------------------------------------------------------------------------
/JsRefresher/asyncCounters.js:
--------------------------------------------------------------------------------
1 | let count =0;
2 |
3 | function setIntervalCounter() {
4 | function increment() {
5 | count++;
6 | console.clear();
7 | console.log(count);
8 | if (count >= 70) {
9 | console.clear();
10 | clearInterval(countId);
11 | }
12 | }
13 |
14 | let countId = setInterval(increment, 1000);
15 | }
16 | setIntervalCounter();
17 |
18 | function setTimeoutwalaCounter() {
19 | function increment() {
20 | count++;
21 | console.clear();
22 | console.log(count);
23 | }
24 | //user recursion here
25 | let timer = setTimeout(function mytimer() {
26 | increment();
27 | timer = setTimeout(mytimer, 1000);
28 | }, 1000);
29 |
30 | setTimeout(() => {
31 | console.log('Timer is Dead');
32 | clearTimeout(timer);
33 | }, 8000);
34 | }
35 |
36 | setTimeoutwalaCounter();
--------------------------------------------------------------------------------
/JsRefresher/expenditure-analysis.js:
--------------------------------------------------------------------------------
1 | /*
2 | Implement a function `calculateTotalSpentByCategory` which takes a list of transactions as parameter
3 | and return a list of objects where each object is unique category-wise and has total price spent as its value.
4 | Transaction - an object like { itemName, category, price, timestamp }.
5 | Output - [{ category1 - total_amount_spent_on_category1 }, { category2 - total_amount_spent_on_category2 }]
6 |
7 | Once you've implemented the logic, test your code by running
8 | - `npm run test-expenditure-analysis`
9 | */
10 |
11 | function calculateTotalSpentByCategory(transactions) {
12 | const categoryBox = {};
13 | //now we aim to create categoryBox = { Food: 30, Clothing: 15 } which is {category: categoryBox[category]or simply sum of prices for particular category}
14 | for (let transaction of transactions) {
15 | const { category, price } = transaction;
16 | if (categoryBox.hasOwnProperty(category)) {
17 | categoryBox[category] += price;
18 | console.log(categoryBox);
19 | } else {
20 | categoryBox[category] = price;
21 | console.log(categoryBox);
22 | }
23 | }
24 | const result = [];
25 | for (const category in categoryBox) {
26 | result.push({ category, totalSpent: categoryBox[category] });
27 | }
28 |
29 | return result;
30 | }
31 |
32 | module.exports = calculateTotalSpentByCategory;
33 |
--------------------------------------------------------------------------------
/JsRefresher/refresher.js:
--------------------------------------------------------------------------------
1 | // Question1: print sum
2 |
3 | function sum(n) {
4 | let sum = 0;
5 | for (let i = 0; i < n; i++) {
6 | sum = sum + i;
7 | }
8 | return sum;
9 | }
10 |
11 | console.log(sum(100));
12 |
13 | //print in range
14 | function rangeSum(start, end){
15 | let sum=0;
16 | for(let i=start;i<=end;i++){
17 | sum= sum+i;
18 | }
19 | return sum;
20 | }
21 | console.log (rangeSum(1,100));
22 |
23 | //2. fibbonaci
24 |
25 | function fibo(n){
26 | if(n<=1){
27 | return n;
28 | }
29 | let a=0;
30 | let b =1;
31 | let c;
32 |
33 | for(let i =2;i<=n;i++){
34 | c= a+b;
35 | a= b;
36 | b=c;
37 | }
38 | return b;
39 | }
40 | console.log(fib0(10));
41 |
42 | function fib(n) {
43 | if (n <= 1) {
44 | return n;
45 | }
46 | return fib(n - 1) + fib(n - 2);
47 | }
48 | console.log(fib(10));
49 |
50 | //3. pattern
51 | // *
52 | // **
53 | // ***
54 | // ****
55 | function starPat(n) {
56 | for (let i = 1; i <= n; i++) {
57 | let pat = '';
58 | for (let j = 1; j <= i; j++) {
59 | pat += '* ';
60 | }
61 | console.log(pat);
62 | }
63 | }
64 |
65 | starPat(5);
66 |
67 | // 4. starpattern
68 | // **
69 | // ****
70 | // ******
71 | // ********
72 |
73 | function fatPat(n) {
74 | for (let i = 1; i <= n; i++) {
75 | let pat = '';
76 | for (let j = 1; j <= i; j++) {
77 | pat += '**';
78 | }
79 | console.log(pat);
80 | }
81 | }
82 | fatPat(5);
83 |
--------------------------------------------------------------------------------
/JsRefresher/todolist.js:
--------------------------------------------------------------------------------
1 | /*
2 | Implement a class `Todo` having below methods
3 | - add(todo): adds todo to list of todos
4 | - remove(indexOfTodo): remove todo from list of todos
5 | - update(index, updatedTodo): update todo at given index
6 | - getAll: returns all todos
7 | - get(indexOfTodo): returns todo at given index
8 | - clear: deletes all todos
9 |
10 | Once you've implemented the logic, test your code by running
11 | - `npm run test-todo-list`
12 | */
13 |
14 | class Todo {
15 | constructor() {
16 | this.items = [];
17 | }
18 | add(item) {
19 | this.items.push(item);
20 | }
21 | remove(index) {
22 | if (index >= 0 && index < this.items.length) {
23 | this.items.splice(index, 1);
24 | }
25 | }
26 | update(index, updatedTodo) {
27 | if (index >= 0 && index < this.items.length) {
28 | this.items[index] = updatedTodo;
29 | }
30 | }
31 | getAll() {
32 | return this.items;
33 | }
34 | get(index) {
35 | if (index >= 0 && index < this.items.length) {
36 | return this.items[index];
37 | }
38 | return null;
39 | }
40 | clear() {
41 | return this.items.splice(0, this.items.length);
42 | }
43 | }
44 |
45 | module.exports = Todo;
46 |
--------------------------------------------------------------------------------
/Prisma/.gitignore:
--------------------------------------------------------------------------------
1 | dist
2 | node_modules
3 | # Keep environment variables out of version control
4 | .env
5 |
--------------------------------------------------------------------------------
/Prisma/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "week-13-prisma",
3 | "version": "1.0.0",
4 | "main": "index.js",
5 | "license": "MIT",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "keywords": [],
10 | "author": "",
11 | "description": "",
12 | "devDependencies": {
13 | "@types/node": "^20.5.9",
14 | "prisma": "^5.2.0",
15 | "ts-node": "^10.9.1",
16 | "typescript": "^5.2.2"
17 | },
18 | "dependencies": {
19 | "@prisma/client": "^5.2.0"
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/Prisma/src/01-create-user.ts:
--------------------------------------------------------------------------------
1 |
2 | import { PrismaClient } from '@prisma/client'
3 |
4 | const prisma = new PrismaClient()
5 |
6 | async function main() {
7 | await prisma.user.create({
8 | data: {
9 | email: "harkirat1@gmail.com",
10 | name: "harkriat"
11 | }
12 | })
13 | }
14 |
15 | main()
16 | .then(async () => {
17 | console.log("done");
18 | await prisma.$disconnect()
19 | })
20 | .catch(async (e) => {
21 | console.error(e)
22 | await prisma.$disconnect()
23 | process.exit(1)
24 | })
--------------------------------------------------------------------------------
/Prisma/src/02-crate-post.ts:
--------------------------------------------------------------------------------
1 |
2 | import { PrismaClient } from '@prisma/client'
3 |
4 | const prisma = new PrismaClient()
5 |
6 | async function main() {
7 | await prisma.post.create({
8 | data: {
9 | title: "title of post",
10 | author: {
11 | connect: {
12 | id: 1
13 | }
14 | }
15 | }
16 | })
17 | }
18 |
19 | main()
20 | .then(async () => {
21 | console.log("done");
22 | await prisma.$disconnect()
23 | })
24 | .catch(async (e) => {
25 | console.error(e)
26 | await prisma.$disconnect()
27 | process.exit(1)
28 | })
--------------------------------------------------------------------------------
/Prisma/src/03-create-user-and-post.ts:
--------------------------------------------------------------------------------
1 |
2 | import { PrismaClient } from '@prisma/client'
3 |
4 | const prisma = new PrismaClient()
5 |
6 | async function main() {
7 | await prisma.user.create({
8 | data: {
9 | email: "harkirat3@gmail.com",
10 | name: "harkriat",
11 | posts: {
12 | create: [
13 | {
14 | title: "harkirats title1"
15 | },
16 | {
17 | title: "harkirats title2"
18 | },
19 | ]
20 | }
21 | }
22 | })
23 | }
24 |
25 | main()
26 | .then(async () => {
27 | console.log("done");
28 | await prisma.$disconnect()
29 | })
30 | .catch(async (e) => {
31 | console.error(e)
32 | await prisma.$disconnect()
33 | process.exit(1)
34 | })
--------------------------------------------------------------------------------
/Prisma/src/04-get-user.ts:
--------------------------------------------------------------------------------
1 |
2 |
3 | import { PrismaClient } from '@prisma/client'
4 |
5 | const prisma = new PrismaClient()
6 |
7 | async function main() {
8 | const users = await prisma.user.findMany({});
9 | console.log(users);
10 | const user = await prisma.user.findUnique({
11 | where: {
12 | id: 1
13 | },
14 | include: {
15 | posts: true
16 | }
17 | });
18 | console.log(user);
19 | };
20 |
21 | main()
22 | .then(async () => {
23 | console.log("done");
24 | await prisma.$disconnect()
25 | })
26 | .catch(async (e) => {
27 | console.error(e)
28 | await prisma.$disconnect()
29 | process.exit(1)
30 | })
--------------------------------------------------------------------------------
/Prisma/src/05-get-post.ts:
--------------------------------------------------------------------------------
1 | import { PrismaClient } from '@prisma/client'
2 |
3 | const prisma = new PrismaClient({log: ['info', 'query'],})
4 |
5 | async function main() {
6 | const posts = await prisma.post.findMany({
7 | include: {
8 | author: {
9 | select: {
10 | email: true
11 | }
12 | }
13 | }
14 | });
15 | console.log(posts);
16 | };
17 |
18 | main()
19 | .then(async () => {
20 | console.log("done");
21 | await prisma.$disconnect()
22 | })
23 | .catch(async (e) => {
24 | console.error(e)
25 | await prisma.$disconnect()
26 | process.exit(1)
27 | })
--------------------------------------------------------------------------------
/Prisma/src/06-debug-logs.ts:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | import { PrismaClient } from '@prisma/client'
5 |
6 | const prisma = new PrismaClient({log: ['info', 'query'],})
7 |
8 | async function main() {
9 | const users = await prisma.user.findMany({});
10 | console.log(users);
11 | const user = await prisma.user.findUnique({
12 | where: {
13 | id: 1
14 | },
15 | include: {
16 | posts: true
17 | }
18 | });
19 | console.log(user);
20 | };
21 |
22 | main()
23 | .then(async () => {
24 | console.log("done");
25 | await prisma.$disconnect()
26 | })
27 | .catch(async (e) => {
28 | console.error(e)
29 | await prisma.$disconnect()
30 | process.exit(1)
31 | })
--------------------------------------------------------------------------------
/Prisma/src/07-update-user.ts:
--------------------------------------------------------------------------------
1 |
2 | import { PrismaClient } from '@prisma/client'
3 |
4 | const prisma = new PrismaClient()
5 |
6 | async function main() {
7 | await prisma.user.update({
8 | where: {
9 | id: 1
10 | },
11 | data: {
12 | name: "harkiratsingh2"
13 | }
14 | })
15 | }
16 |
17 | main()
18 | .then(async () => {
19 | console.log("done");
20 | await prisma.$disconnect()
21 | })
22 | .catch(async (e) => {
23 | console.error(e)
24 | await prisma.$disconnect()
25 | process.exit(1)
26 | })
--------------------------------------------------------------------------------
/Prisma/src/08-delete-unpublished-posts.ts:
--------------------------------------------------------------------------------
1 |
2 | import { PrismaClient } from '@prisma/client'
3 |
4 | const prisma = new PrismaClient()
5 |
6 | async function main() {
7 | await prisma.user.update({
8 | where: {
9 | id: 1
10 | },
11 | data: {
12 | posts: {
13 | deleteMany: {
14 | published: false
15 | }
16 | }
17 | }
18 | })
19 | }
20 |
21 | main()
22 | .then(async () => {
23 | console.log("done");
24 | await prisma.$disconnect()
25 | })
26 | .catch(async (e) => {
27 | console.error(e)
28 | await prisma.$disconnect()
29 | process.exit(1)
30 | })
--------------------------------------------------------------------------------
/Prisma/src/advance-debug/debug.ts:
--------------------------------------------------------------------------------
1 | /// https://github.com/prisma/prisma/issues/5026
2 |
3 | import { PrismaClient } from '@prisma/client'
4 |
5 | const prisma = new PrismaClient({
6 | log: [
7 | {
8 | emit: "event",
9 | level: "query",
10 | },
11 | ],
12 | })
13 |
14 | async function main() {
15 | const users = await prisma.user.findMany({
16 | take: 2,
17 | });
18 | };
19 |
20 | main()
21 | .then(async () => {
22 | console.log("done");
23 | await prisma.$disconnect()
24 | })
25 | .catch(async (e) => {
26 | console.error(e)
27 | await prisma.$disconnect()
28 | process.exit(1)
29 | })
30 |
31 | prisma.$on("query", async (e) => {
32 | console.log(`${e.query} ${e.params}`)
33 | });
--------------------------------------------------------------------------------
/Prisma/src/filtering/01-ends-with.ts:
--------------------------------------------------------------------------------
1 |
2 | import { PrismaClient } from '@prisma/client'
3 |
4 | const prisma = new PrismaClient({
5 | log: ['info', 'query']
6 | })
7 |
8 | async function main() {
9 | let res = await prisma.user.findMany({
10 | where: {
11 | email: {
12 | endsWith: 'gmail.com',
13 | },
14 | posts: {
15 | /// Has atleast one post published
16 | some: {
17 | published: true,
18 | },
19 | },
20 | },
21 | include: {
22 | posts: {
23 | where: {
24 | published: true,
25 | },
26 | },
27 | },
28 | })
29 | console.log(res);
30 |
31 | }
32 |
33 | main()
34 | .then(async () => {
35 | console.log("done");
36 | await prisma.$disconnect()
37 | })
38 | .catch(async (e) => {
39 | console.error(e)
40 | await prisma.$disconnect()
41 | process.exit(1)
42 | })
--------------------------------------------------------------------------------
/Prisma/src/filtering/02-limits-and-offsets.ts:
--------------------------------------------------------------------------------
1 |
2 | import { PrismaClient } from '@prisma/client'
3 |
4 | const prisma = new PrismaClient({
5 | log: ['info', 'query']
6 | })
7 |
8 | async function main() {
9 | let res = await prisma.post.findMany({
10 | take: 3
11 | })
12 | console.log(res);
13 |
14 | }
15 |
16 | main()
17 | .then(async () => {
18 | console.log("done");
19 | await prisma.$disconnect()
20 | })
21 | .catch(async (e) => {
22 | console.error(e)
23 | await prisma.$disconnect()
24 | process.exit(1)
25 | })
--------------------------------------------------------------------------------
/PrismaPRactice/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | .env
--------------------------------------------------------------------------------
/PrismaPRactice/dist/create-user.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4 | return new (P || (P = Promise))(function (resolve, reject) {
5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8 | step((generator = generator.apply(thisArg, _arguments || [])).next());
9 | });
10 | };
11 | Object.defineProperty(exports, "__esModule", { value: true });
12 | const client_1 = require("@prisma/client");
13 | const prisma = new client_1.PrismaClient();
14 | function main() {
15 | return __awaiter(this, void 0, void 0, function* () {
16 | // ... you will write your Prisma Client queries here
17 | const user = yield prisma.user.create({
18 | data: {
19 | name: 'Alice',
20 | email: 'alice@prisma.io',
21 | },
22 | });
23 | console.log(user);
24 | });
25 | }
26 | main()
27 | .then(() => __awaiter(void 0, void 0, void 0, function* () {
28 | yield prisma.$disconnect();
29 | }))
30 | .catch((e) => __awaiter(void 0, void 0, void 0, function* () {
31 | console.error(e);
32 | yield prisma.$disconnect();
33 | process.exit(1);
34 | }));
35 |
--------------------------------------------------------------------------------
/PrismaPRactice/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "prismapractice",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "keywords": [],
10 | "author": "",
11 | "license": "ISC",
12 | "devDependencies": {
13 | "@types/node": "^20.8.2",
14 | "prisma": "^5.3.1",
15 | "ts-node": "^10.9.1",
16 | "typescript": "^5.2.2"
17 | },
18 | "dependencies": {
19 | "@prisma/client": "^5.3.1"
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/PrismaPRactice/prisma/migrations/20231004081953_init/migration.sql:
--------------------------------------------------------------------------------
1 | -- CreateTable
2 | CREATE TABLE "User" (
3 | "id" SERIAL NOT NULL,
4 | "email" TEXT NOT NULL,
5 | "name" TEXT,
6 |
7 | CONSTRAINT "User_pkey" PRIMARY KEY ("id")
8 | );
9 |
10 | -- CreateTable
11 | CREATE TABLE "Post" (
12 | "id" SERIAL NOT NULL,
13 | "title" TEXT NOT NULL,
14 | "content" TEXT,
15 | "published" BOOLEAN NOT NULL DEFAULT false,
16 | "authorId" INTEGER NOT NULL,
17 |
18 | CONSTRAINT "Post_pkey" PRIMARY KEY ("id")
19 | );
20 |
21 | -- CreateIndex
22 | CREATE UNIQUE INDEX "User_email_key" ON "User"("email");
23 |
24 | -- AddForeignKey
25 | ALTER TABLE "Post" ADD CONSTRAINT "Post_authorId_fkey" FOREIGN KEY ("authorId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
26 |
--------------------------------------------------------------------------------
/PrismaPRactice/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"
--------------------------------------------------------------------------------
/PrismaPRactice/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 User {
14 | id Int @id @default(autoincrement())
15 | email String @unique
16 | name String?
17 | posts Post[]
18 | }
19 |
20 | model Post {
21 | id Int @id @default(autoincrement())
22 | title String
23 | content String?
24 | published Boolean @default(false)
25 | author User @relation(fields: [authorId], references: [id])
26 | authorId Int
27 | }
28 |
--------------------------------------------------------------------------------
/PrismaPRactice/src/02-crate-post.ts:
--------------------------------------------------------------------------------
1 |
2 | import { PrismaClient } from '@prisma/client'
3 |
4 | const prisma = new PrismaClient({log:['info', 'query']})
5 |
6 | async function main() {
7 | await prisma.post.create({
8 | data: {
9 | title: "title of post",
10 | published:true,
11 | author: {
12 | connect: {
13 | id: 1
14 | }
15 | }
16 | }
17 | })
18 | }
19 |
20 | main()
21 | .then(async () => {
22 | console.log("done");
23 | await prisma.$disconnect()
24 | })
25 | .catch(async (e) => {
26 | console.error(e)
27 | await prisma.$disconnect()
28 | process.exit(1)
29 | })
--------------------------------------------------------------------------------
/PrismaPRactice/src/create-user.ts:
--------------------------------------------------------------------------------
1 | import { PrismaClient } from '@prisma/client'
2 |
3 | const prisma = new PrismaClient()
4 |
5 | async function main() {
6 | // ... you will write your Prisma Client queries here
7 | const user = await prisma.user.create({
8 | data: {
9 | name: 'Alice',
10 | email: 'alice@prisma.io',
11 | },
12 | })
13 | console.log(user)
14 | }
15 |
16 | main()
17 | .then(async () => {
18 | await prisma.$disconnect()
19 | })
20 | .catch(async (e) => {
21 | console.error(e)
22 | await prisma.$disconnect()
23 | process.exit(1)
24 | })
25 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # 100xdevsCohort
2 | It's a Collection of all the practice problems i solve during the live classes of 100xDevs.
3 |
4 |
--------------------------------------------------------------------------------
/SQL/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | dist
3 |
--------------------------------------------------------------------------------
/SQL/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "sql-commands",
3 | "version": "1.0.0",
4 | "main": "index.js",
5 | "license": "MIT",
6 | "scripts": {
7 | "build": "tsc -b"
8 | },
9 | "dependencies": {
10 | "@types/pg": "^8.10.2",
11 | "pg": "^8.11.3"
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/SQL/src/create-index.ts:
--------------------------------------------------------------------------------
1 | import { getClient } from "./utils";
2 |
3 | async function addIndex() {
4 | const client = await getClient();
5 |
6 | const createIndexQuery = 'CREATE INDEX idx_todos_user_id ON todos(user_id)';
7 | await client.query(createIndexQuery);
8 |
9 | console.log("Index added successfully on user_id column of todos table!");
10 | }
11 |
12 | addIndex();
13 |
--------------------------------------------------------------------------------
/SQL/src/create-table.ts:
--------------------------------------------------------------------------------
1 | import { getClient } from "./utils";
2 |
3 | async function createTable() {
4 | const createUserTableQuery = `
5 | CREATE TABLE users (
6 | id SERIAL PRIMARY KEY,
7 | email VARCHAR(255) UNIQUE NOT NULL,
8 | password VARCHAR(255) NOT NULL
9 | );
10 | `;
11 |
12 | const client = await getClient();
13 |
14 | await client.query(createUserTableQuery);
15 |
16 | const createTodosQuery = `
17 | CREATE TABLE todos (
18 | id SERIAL PRIMARY KEY,
19 | title TEXT NOT NULL,
20 | description TEXT,
21 | user_id INTEGER REFERENCES users(id),
22 | done BOOLEAN DEFAULT FALSE
23 | );
24 | `;
25 |
26 |
27 | await client.query(createTodosQuery);
28 |
29 | console.log("Table created successfully!");
30 | }
31 |
32 |
33 |
34 | createTable();
--------------------------------------------------------------------------------
/SQL/src/delete-data.ts:
--------------------------------------------------------------------------------
1 | import { getClient } from "./utils";
2 |
3 | async function deleteTodo(todoId: number) {
4 | const client = await getClient();
5 |
6 | const deleteTodoText = 'DELETE FROM todos WHERE id = $1';
7 | await client.query(deleteTodoText, [todoId]);
8 |
9 | console.log(`Todo with ID ${todoId} deleted!`);
10 | }
11 |
12 | const todoIdToDelete = 1;
13 | deleteTodo(todoIdToDelete);
14 |
--------------------------------------------------------------------------------
/SQL/src/get-data.ts:
--------------------------------------------------------------------------------
1 | import { getClient } from "./utils";
2 |
3 | async function getUsers() {
4 | const client = await getClient();
5 |
6 | const selectUsersText = 'SELECT * FROM users';
7 | const userRes = await client.query(selectUsersText);
8 |
9 | console.log("Users:");
10 | for (let user of userRes.rows) {
11 | console.log(`ID: ${user.id}, Email: ${user.email}`);
12 | }
13 | }
14 |
15 | async function getUserFromEmail(email: string) {
16 | const client = await getClient();
17 |
18 | const selectUserText = 'SELECT * FROM users WHERE email = $1';
19 | const userRes = await client.query(selectUserText, [email]);
20 |
21 | console.log("Single User detail:");
22 | for (let user of userRes.rows) {
23 | console.log(`ID: ${user.id}, Email: ${user.email}`);
24 | }
25 | }
26 |
27 | async function getTodosForUser(userId: number) {
28 | const client = await getClient();
29 |
30 | const selectTodosText = 'SELECT * FROM todos WHERE user_id = $1';
31 | const todoRes = await client.query(selectTodosText, [userId]);
32 |
33 | console.log(`Todos for User ID ${userId}:`);
34 | for (let todo of todoRes.rows) {
35 | console.log(`ID: ${todo.id}, Title: ${todo.title}, Description: ${todo.description}, Done: ${todo.done}`);
36 | }
37 | }
38 |
39 | getUsers();
40 |
41 | getUserFromEmail("ajaydeep@gmail.com")
42 |
43 | const userIdToFetch = 1;
44 | getTodosForUser(userIdToFetch);
--------------------------------------------------------------------------------
/SQL/src/insert-data.ts:
--------------------------------------------------------------------------------
1 | import { getClient } from "./utils";
2 |
3 | async function createEntries() {
4 | const client = await getClient();
5 | const insertUserText = 'INSERT INTO users (email, password) VALUES ($1, $2) RETURNING id';
6 | const userValues = ['ajaydeepsingh@gmail.com', 'hashed_password_here'];
7 |
8 | let response = await client.query(insertUserText, userValues);
9 | const insertTodoText = 'INSERT INTO todos (title, description, user_id, done) VALUES ($1, $2, $3, $4) RETURNING id';
10 | const todoValues = ['Buy groceries', 'Milk, bread, and eggs', response.rows[0].id, false];
11 | await client.query(insertTodoText, todoValues);
12 |
13 | console.log("Entries created!");
14 | }
15 |
16 |
17 |
18 | createEntries();
19 |
20 | //in insertUserText, the reason behind using $1, $2 is to prevent SQL injection. If we write definitive value their, some user might send some harmful query and delete our table
--------------------------------------------------------------------------------
/SQL/src/joins/advance-1.ts:
--------------------------------------------------------------------------------
1 | // FULL JOIN :-> should be present in either tables
2 | // Inner JOin : should be present in both the tables
3 | //Left Join : Should have all the entries from the left table
4 | //right join: Should have all the entries from the right table
5 |
6 | import { getClient } from "../utils";
7 |
8 | // Get all todos for a give user
9 | // This needs to ensure that every user comes atleast once
10 | async function getUserAndTodosWithJoin(userId: number) {
11 | const client = await getClient();
12 |
13 | const joinQuery = `
14 | SELECT users.*, todos.title, todos.description, todos.done
15 | FROM users
16 | LEFT JOIN todos ON users.id = todos.user_id
17 | WHERE users.id = $1;
18 | `;
19 |
20 | const res = await client.query(joinQuery, [userId]);
21 | const results = res.rows;
22 |
23 | console.log("User and Todos:", results);
24 | }
25 |
26 | getUserAndTodosWithJoin(1)
--------------------------------------------------------------------------------
/SQL/src/joins/advance-2.ts:
--------------------------------------------------------------------------------
1 | import { getClient } from "../utils";
2 |
3 | // Get all todos for a give user
4 | // This shouldnt return a row if no todos exist for the user
5 | async function getUserAndTodosWithJoin(userId: number) {
6 | const client = await getClient();
7 |
8 | const joinQuery = `
9 | SELECT users.*, todos.title, todos.description, todos.done
10 | FROM users
11 | JOIN todos ON users.id = todos.user_id
12 | WHERE users.id = $1;
13 | `;
14 |
15 | const res = await client.query(joinQuery, [userId]);
16 | const results = res.rows;
17 |
18 | console.log("User and Todos:", results);
19 | }
20 |
21 | getUserAndTodosWithJoin(5)
--------------------------------------------------------------------------------
/SQL/src/joins/advance-3.ts:
--------------------------------------------------------------------------------
1 | import { getClient } from "../utils";
2 |
3 | async function getAllTodosWithUserDetails() {
4 | const client = await getClient();
5 |
6 | const joinQuery = `
7 | SELECT todos.*, users.email, users.password
8 | FROM todos
9 | JOIN users ON todos.user_id = users.id;
10 | `;
11 |
12 | const res = await client.query(joinQuery);
13 | const results = res.rows;
14 |
15 | console.log("Todos with User Details:", results);
16 | }
17 |
18 | getAllTodosWithUserDetails();
19 |
--------------------------------------------------------------------------------
/SQL/src/joins/basic.ts:
--------------------------------------------------------------------------------
1 | import { getClient } from "../utils";
2 |
3 | async function getUserAndTodosSeparateQueries(userId: number) {
4 | const client = await getClient();
5 |
6 | // Fetch user details
7 | const userQuery = 'SELECT * FROM users WHERE id = $1';
8 | const userRes = await client.query(userQuery, [userId]);
9 | const user = userRes.rows[0];
10 |
11 | // Fetch todos for the user
12 | const todosQuery = 'SELECT * FROM todos WHERE user_id = $1';
13 | const todosRes = await client.query(todosQuery, [userId]);
14 | const todos = todosRes.rows;
15 |
16 | console.log("User Details:", user);
17 | console.log("Todos:", todos);
18 | }
19 |
20 | getUserAndTodosSeparateQueries(1);
--------------------------------------------------------------------------------
/SQL/src/update-data.ts:
--------------------------------------------------------------------------------
1 | import { getClient } from "./utils";
2 |
3 | async function updateTodo(todoId: number) {
4 | const client = await getClient();
5 |
6 | const updateTodoText = 'UPDATE todos SET done = $1 WHERE id = $2';
7 | await client.query(updateTodoText, [true, todoId]);
8 |
9 | console.log(`Todo with ID ${todoId} updated to done!`);
10 | }
11 |
12 | const todoIdToUpdate = 1;
13 | updateTodo(todoIdToUpdate);
14 |
--------------------------------------------------------------------------------
/SQL/src/utils.ts:
--------------------------------------------------------------------------------
1 | import { Client } from 'pg';
2 |
3 | export async function getClient() {
4 | const client = new Client("URL of db");
5 | await client.connect();
6 | return client;
7 | }
8 |
--------------------------------------------------------------------------------
/SQL/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es2016",
4 | "module": "commonjs",
5 | "esModuleInterop": true,
6 | "forceConsistentCasingInFileNames": true,
7 | "strict": true,
8 | "skipLibCheck": true,
9 | "rootDir": "src",
10 | "outDir": "dist"
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/Week4/index.js:
--------------------------------------------------------------------------------
1 | function double(arr){
2 | const double = arr.map(el=>{
3 | return el*2
4 | })
5 | console.log(double)
6 | }
7 |
8 | let arr = [1,2,3,4,5,6]
9 | double(arr);
--------------------------------------------------------------------------------
/node_modules/.package-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "100xdevs",
3 | "lockfileVersion": 3,
4 | "requires": true,
5 | "packages": {}
6 | }
7 |
--------------------------------------------------------------------------------
/package-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "100xdevs",
3 | "lockfileVersion": 3,
4 | "requires": true,
5 | "packages": {}
6 | }
7 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {}
2 |
--------------------------------------------------------------------------------
/week-10/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ajaydeep123/100xdevsCohort/20b7c0ac5444177a23e8b3bf298adb3c3be87057/week-10/.DS_Store
--------------------------------------------------------------------------------
/week-10/.gitignore:
--------------------------------------------------------------------------------
1 | admin-client/node_modules
2 | .idea
3 |
--------------------------------------------------------------------------------
/week-10/admin-client/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ajaydeep123/100xdevsCohort/20b7c0ac5444177a23e8b3bf298adb3c3be87057/week-10/admin-client/.DS_Store
--------------------------------------------------------------------------------
/week-10/admin-client/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Vite + React
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/week-10/admin-client/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vite-project",
3 | "private": true,
4 | "version": "0.0.0",
5 | "type": "module",
6 | "scripts": {
7 | "dev": "vite",
8 | "build": "vite build",
9 | "lint": "eslint src --ext js,jsx --report-unused-disable-directives --max-warnings 0",
10 | "preview": "vite preview"
11 | },
12 | "dependencies": {
13 | "@emotion/react": "^11.11.1",
14 | "@emotion/styled": "^11.11.0",
15 | "@mui/material": "^5.13.7",
16 | "axios": "^1.4.0",
17 | "cookie-parser": "^1.4.6",
18 | "react": "^18.2.0",
19 | "react-dom": "^18.2.0",
20 | "react-router-dom": "^6.14.1",
21 | "recoil": "^0.7.7"
22 | },
23 | "devDependencies": {
24 | "@types/react": "^18.2.14",
25 | "@types/react-dom": "^18.2.6",
26 | "@vitejs/plugin-react": "^4.0.1",
27 | "eslint": "^8.44.0",
28 | "eslint-plugin-react": "^7.32.2",
29 | "eslint-plugin-react-hooks": "^4.6.0",
30 | "eslint-plugin-react-refresh": "^0.4.1",
31 | "vite": "^4.4.0"
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/week-10/admin-client/public/class.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ajaydeep123/100xdevsCohort/20b7c0ac5444177a23e8b3bf298adb3c3be87057/week-10/admin-client/public/class.jpeg
--------------------------------------------------------------------------------
/week-10/admin-client/public/vite.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/week-10/admin-client/src/App.css:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ajaydeep123/100xdevsCohort/20b7c0ac5444177a23e8b3bf298adb3c3be87057/week-10/admin-client/src/App.css
--------------------------------------------------------------------------------
/week-10/admin-client/src/components/Loading.jsx:
--------------------------------------------------------------------------------
1 | import {CircularProgress} from "@mui/material";
2 |
3 | export const Loading = () => {
4 | return
9 | }
--------------------------------------------------------------------------------
/week-10/admin-client/src/config.js:
--------------------------------------------------------------------------------
1 | export const BASE_URL = 'http://localhost:3000';
--------------------------------------------------------------------------------
/week-10/admin-client/src/index.css:
--------------------------------------------------------------------------------
1 | body {
2 | margin: 0px;
3 | }
--------------------------------------------------------------------------------
/week-10/admin-client/src/main.jsx:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import ReactDOM from 'react-dom/client'
3 | import App from './App.jsx'
4 | import './index.css'
5 |
6 | ReactDOM.createRoot(document.getElementById('root')).render(
7 |
8 |
9 | ,
10 | )
11 |
--------------------------------------------------------------------------------
/week-10/admin-client/src/store/atoms/course.js:
--------------------------------------------------------------------------------
1 | import {atom} from "recoil";
2 |
3 | export const courseState = atom({
4 | key: 'courseState',
5 | default: {
6 | isLoading: true,
7 | course: null
8 | },
9 | });
10 |
--------------------------------------------------------------------------------
/week-10/admin-client/src/store/atoms/user.js:
--------------------------------------------------------------------------------
1 | import {atom} from "recoil";
2 |
3 | export const userState = atom({
4 | key: 'userState',
5 | default: {
6 | isLoading: true,
7 | userEmail: null
8 | },
9 | });
10 |
--------------------------------------------------------------------------------
/week-10/admin-client/src/store/selectors/course.js:
--------------------------------------------------------------------------------
1 | import { userState } from "../atoms/user";
2 | import {selector} from "recoil";
3 | import { courseState } from "../atoms/course";
4 |
5 | export const isCourseLoading = selector({
6 | key: 'isCourseLoaingState',
7 | get: ({get}) => {
8 | const state = get(courseState);
9 |
10 | return state.isLoading;
11 | },
12 | });
13 |
14 | export const courseDetails = selector({
15 | key: 'courseDetailsState',
16 | get: ({get}) => {
17 | const state = get(courseState);
18 |
19 | return state.course;
20 | },
21 | });
22 |
23 | export const courseTitle = selector({
24 | key: 'courseTitleState',
25 | get: ({get}) => {
26 | const state = get(courseState);
27 | if (state.course) {
28 | return state.course.title;
29 | }
30 | return "";
31 | },
32 | });
33 |
34 | export const coursePrice = selector({
35 | key: 'coursePriceState',
36 | get: ({get}) => {
37 | const state = get(courseState);
38 | if (state.course) {
39 | return state.course.price;
40 | }
41 | return "";
42 | },
43 | });
44 |
45 | export const courseImage = selector({
46 | key: 'courseImageState',
47 | get: ({get}) => {
48 | const state = get(courseState);
49 | if (state.course) {
50 | return state.course.image;
51 | }
52 | return "";
53 | },
54 | });
55 |
56 |
--------------------------------------------------------------------------------
/week-10/admin-client/src/store/selectors/isUserLoading.js:
--------------------------------------------------------------------------------
1 | import { userState } from "../atoms/user";
2 | import {selector} from "recoil";
3 |
4 | export const isUserLoading = selector({
5 | key: 'userLoadingState',
6 | get: ({get}) => {
7 | const state = get(userState);
8 |
9 | return state.isLoading;
10 | },
11 | });
12 |
--------------------------------------------------------------------------------
/week-10/admin-client/src/store/selectors/userEmail.js:
--------------------------------------------------------------------------------
1 |
2 | import { userState } from "../atoms/user";
3 | import {selector} from "recoil";
4 |
5 | export const userEmailState = selector({
6 | key: 'userEmailState',
7 | get: ({get}) => {
8 | const state = get(userState);
9 |
10 | return state.userEmail;
11 | },
12 | });
13 |
--------------------------------------------------------------------------------
/week-10/admin-client/src/utils.js:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ajaydeep123/100xdevsCohort/20b7c0ac5444177a23e8b3bf298adb3c3be87057/week-10/admin-client/src/utils.js
--------------------------------------------------------------------------------
/week-10/admin-client/vite.config.js:
--------------------------------------------------------------------------------
1 | import { defineConfig } from 'vite'
2 | import react from '@vitejs/plugin-react'
3 |
4 | // https://vitejs.dev/config/
5 | export default defineConfig({
6 | plugins: [react()],
7 | })
8 |
--------------------------------------------------------------------------------
/week-10/server/.gitignore:
--------------------------------------------------------------------------------
1 | public
2 | node_modules
3 |
--------------------------------------------------------------------------------
/week-10/server/db/index.js:
--------------------------------------------------------------------------------
1 | const mongoose = require("mongoose");
2 | // Define mongoose schemas
3 | const userSchema = new mongoose.Schema({
4 | username: {type: String},
5 | password: String,
6 | purchasedCourses: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Course' }]
7 | });
8 |
9 | const adminSchema = new mongoose.Schema({
10 | username: String,
11 | password: String
12 | });
13 |
14 | const courseSchema = new mongoose.Schema({
15 | title: String,
16 | description: String,
17 | price: Number,
18 | imageLink: String,
19 | published: Boolean
20 | });
21 |
22 | const User = mongoose.model('User', userSchema);
23 | const Admin = mongoose.model('Admin', adminSchema);
24 | const Course = mongoose.model('Course', courseSchema);
25 |
26 | module.exports = {
27 | User,
28 | Admin,
29 | Course
30 | }
--------------------------------------------------------------------------------
/week-10/server/index.js:
--------------------------------------------------------------------------------
1 | const express = require('express');
2 | const mongoose = require('mongoose');
3 | const cors = require('cors');
4 | const adminRouter = require("./routes/admin");
5 | const userRouter = require("./routes/user");
6 | const path = require("path");
7 | const app = express();
8 |
9 | app.use(cors());
10 | app.use(express.json());
11 |
12 | app.use("/admin", adminRouter)
13 | app.use("/user", userRouter)
14 |
15 | app.use(express.static("public"));
16 | app.use("/*", (req, res) => {
17 | res.sendFile(path.join(__dirname, "/public/index.html"))
18 | })
19 |
20 | // Connect to MongoDB
21 | // DONT MISUSE THIS THANKYOU!!
22 | mongoose.connect('mongodb+srv://kirattechnologies:iRbi4XRDdM7JMMkl@cluster0.e95bnsi.mongodb.net/admin?authSource=admin&replicaSet=atlas-ue73sj-shard-0&readPreference=primary&appname=MongoDB%20Compass&ssl=true', { useNewUrlParser: true, useUnifiedTopology: true, dbName: "courses" });
23 |
24 | app.listen(3000, () => console.log('Server running on port 3000'));
25 |
--------------------------------------------------------------------------------
/week-10/server/middleware/auth.js:
--------------------------------------------------------------------------------
1 | const jwt = require('jsonwebtoken');
2 | const SECRET = 'SECr3t'; // This should be in an environment variable in a real application
3 |
4 | const authenticateJwt = (req, res, next) => {
5 | const authHeader = req.headers.authorization;
6 | if (authHeader) {
7 | const token = authHeader.split(' ')[1];
8 | jwt.verify(token, SECRET, (err, user) => {
9 | if (err) {
10 | return res.sendStatus(403);
11 | }
12 | req.user = user;
13 | next();
14 | });
15 | } else {
16 | res.sendStatus(401);
17 | }
18 | };
19 |
20 | module.exports = {
21 | authenticateJwt,
22 | SECRET
23 | }
--------------------------------------------------------------------------------
/week-10/server/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "server",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "03-course-app-medium.js",
6 | "scripts": {
7 | "dev": "node index.js",
8 | "start": "cd ../admin-client && npm run build && rm -rf ../server/public && mkdir -p ../server/public && mv ./dist/* ../server/public && cd ../server && node index.js"
9 | },
10 | "author": "",
11 | "license": "ISC",
12 | "dependencies": {
13 | "cors": "^2.8.5",
14 | "express": "^4.18.2",
15 | "jsonwebtoken": "^9.0.1",
16 | "mongoose": "^7.3.3"
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/week-10/yarn.lock:
--------------------------------------------------------------------------------
1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2 | # yarn lockfile v1
3 |
4 |
5 |
--------------------------------------------------------------------------------
/week-12-1/classes/node_modules/helpful-decorators/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License
2 |
3 | Copyright (c) 2010-2017 Netanel Basal
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
--------------------------------------------------------------------------------
/week-12-1/classes/node_modules/helpful-decorators/dist-src/bind.js:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * Credit: https://github.com/andreypopp/autobind-decorator/blob/master/src/index.js
4 | * Return a descriptor removing the value and returning a getter
5 | * The getter will return a .bind version of the function
6 | * and memoize the result against a symbol on the instance
7 | */
8 | export function bind(target, key, descriptor) {
9 | let fn = descriptor.value;
10 |
11 | if (typeof fn !== 'function') {
12 | throw new Error(`@autobind decorator can only be applied to methods not: ${typeof fn}`);
13 | } // In IE11 calling Object.defineProperty has a side-effect of evaluating the
14 | // getter for the property which is being replaced. This causes infinite
15 | // recursion and an "Out of stack space" error.
16 |
17 |
18 | let definingProperty = false;
19 | return {
20 | configurable: true,
21 |
22 | get() {
23 | if (definingProperty || this === target.prototype || this.hasOwnProperty(key) || typeof fn !== 'function') {
24 | return fn;
25 | }
26 |
27 | let boundFn = fn.bind(this);
28 | definingProperty = true;
29 | Object.defineProperty(this, key, {
30 | configurable: true,
31 |
32 | get() {
33 | return boundFn;
34 | },
35 |
36 | set(value) {
37 | fn = value;
38 | delete this[key];
39 | }
40 |
41 | });
42 | definingProperty = false;
43 | return boundFn;
44 | },
45 |
46 | set(value) {
47 | fn = value;
48 | }
49 |
50 | };
51 | }
--------------------------------------------------------------------------------
/week-12-1/classes/node_modules/helpful-decorators/dist-src/debounce.js:
--------------------------------------------------------------------------------
1 | const debounceFn = require('lodash.debounce');
2 |
3 | export function debounce(milliseconds = 0, options = {}) {
4 | return function (target, propertyKey, descriptor) {
5 | const map = new WeakMap();
6 | const originalMethod = descriptor.value;
7 |
8 | descriptor.value = function (...params) {
9 | let debounced = map.get(this);
10 |
11 | if (!debounced) {
12 | debounced = debounceFn(originalMethod, milliseconds, options).bind(this);
13 | map.set(this, debounced);
14 | }
15 |
16 | debounced(...params);
17 | };
18 |
19 | return descriptor;
20 | };
21 | }
--------------------------------------------------------------------------------
/week-12-1/classes/node_modules/helpful-decorators/dist-src/delay.js:
--------------------------------------------------------------------------------
1 | export function delay(milliseconds = 0) {
2 | return function (target, propertyKey, descriptor) {
3 | const originalMethod = descriptor.value;
4 |
5 | descriptor.value = function (...args) {
6 | setTimeout(() => {
7 | originalMethod.apply(this, args);
8 | }, milliseconds);
9 | };
10 |
11 | return descriptor;
12 | };
13 | }
--------------------------------------------------------------------------------
/week-12-1/classes/node_modules/helpful-decorators/dist-src/index.js:
--------------------------------------------------------------------------------
1 | export { measure } from "./measure.js";
2 | export { delay } from "./delay.js";
3 | export { debounce } from "./debounce.js";
4 | export { throttle } from "./throttle.js";
5 | export { once } from "./once.js";
6 | export { Mixin } from "./mixin.js";
7 | export { memo } from "./memoize.js";
8 | export { bind } from "./bind.js";
9 | export { SortBy } from "./sortby.js";
--------------------------------------------------------------------------------
/week-12-1/classes/node_modules/helpful-decorators/dist-src/measure.js:
--------------------------------------------------------------------------------
1 | export function measure(target, propertyKey, descriptor) {
2 | const originalMethod = descriptor.value;
3 |
4 | descriptor.value = function (...args) {
5 | const start = performance.now();
6 | const result = originalMethod.apply(this, args);
7 | const end = performance.now();
8 | console.log(`Call to ${propertyKey} took ${(end - start).toFixed(2)} milliseconds.`);
9 | return result;
10 | };
11 |
12 | return descriptor;
13 | }
--------------------------------------------------------------------------------
/week-12-1/classes/node_modules/helpful-decorators/dist-src/memoize.js:
--------------------------------------------------------------------------------
1 | const memoizeFn = require('lodash.memoize');
2 |
3 | export function memo(resolver) {
4 | return function (target, propertyKey, descriptor) {
5 | descriptor.value = memoizeFn(descriptor.value, resolver);
6 | return descriptor;
7 | };
8 | }
--------------------------------------------------------------------------------
/week-12-1/classes/node_modules/helpful-decorators/dist-src/mixin.js:
--------------------------------------------------------------------------------
1 | export function Mixin(baseCtors) {
2 | return function (derivedCtor) {
3 | baseCtors.forEach(baseCtor => {
4 | Object.getOwnPropertyNames(baseCtor.prototype).forEach(name => {
5 | derivedCtor.prototype[name] = baseCtor.prototype[name];
6 | });
7 | });
8 | };
9 | }
--------------------------------------------------------------------------------
/week-12-1/classes/node_modules/helpful-decorators/dist-src/once.js:
--------------------------------------------------------------------------------
1 | const onceFn = require('lodash.once');
2 |
3 | export function once(target, propertyKey, descriptor) {
4 | const originalMethod = descriptor.value;
5 | descriptor.value = onceFn(originalMethod);
6 | return descriptor;
7 | }
--------------------------------------------------------------------------------
/week-12-1/classes/node_modules/helpful-decorators/dist-src/throttle.js:
--------------------------------------------------------------------------------
1 | const throttleFn = require('lodash.throttle');
2 |
3 | export function throttle(milliseconds = 0, options = {}) {
4 | return function (target, propertyKey, descriptor) {
5 | const originalMethod = descriptor.value;
6 | descriptor.value = throttleFn(originalMethod, milliseconds, options);
7 | return descriptor;
8 | };
9 | }
--------------------------------------------------------------------------------
/week-12-1/classes/node_modules/helpful-decorators/dist-types/bind.d.ts:
--------------------------------------------------------------------------------
1 | /**
2 | *
3 | * Credit: https://github.com/andreypopp/autobind-decorator/blob/master/src/index.js
4 | * Return a descriptor removing the value and returning a getter
5 | * The getter will return a .bind version of the function
6 | * and memoize the result against a symbol on the instance
7 | */
8 | export declare function bind(target: any, key: any, descriptor: any): any;
9 |
--------------------------------------------------------------------------------
/week-12-1/classes/node_modules/helpful-decorators/dist-types/debounce.d.ts:
--------------------------------------------------------------------------------
1 | export declare function debounce(milliseconds?: number, options?: {}): any;
2 |
--------------------------------------------------------------------------------
/week-12-1/classes/node_modules/helpful-decorators/dist-types/delay.d.ts:
--------------------------------------------------------------------------------
1 | export declare function delay(milliseconds?: number): any;
2 |
--------------------------------------------------------------------------------
/week-12-1/classes/node_modules/helpful-decorators/dist-types/index.d.ts:
--------------------------------------------------------------------------------
1 | export { measure } from './measure';
2 | export { delay } from './delay';
3 | export { debounce } from './debounce';
4 | export { throttle } from './throttle';
5 | export { once } from './once';
6 | export { Mixin } from './mixin';
7 | export { memo } from './memoize';
8 | export { bind } from './bind';
9 | export { SortBy } from './sortby';
10 |
--------------------------------------------------------------------------------
/week-12-1/classes/node_modules/helpful-decorators/dist-types/measure.d.ts:
--------------------------------------------------------------------------------
1 | export declare function measure(target: any, propertyKey: string, descriptor: PropertyDescriptor): any;
2 |
--------------------------------------------------------------------------------
/week-12-1/classes/node_modules/helpful-decorators/dist-types/memoize.d.ts:
--------------------------------------------------------------------------------
1 | export declare function memo(resolver?: any): any;
2 |
--------------------------------------------------------------------------------
/week-12-1/classes/node_modules/helpful-decorators/dist-types/mixin.d.ts:
--------------------------------------------------------------------------------
1 | export declare function Mixin(baseCtors: Function[]): any;
2 |
--------------------------------------------------------------------------------
/week-12-1/classes/node_modules/helpful-decorators/dist-types/once.d.ts:
--------------------------------------------------------------------------------
1 | export declare function once(target: any, propertyKey: string, descriptor: PropertyDescriptor): any;
2 |
--------------------------------------------------------------------------------
/week-12-1/classes/node_modules/helpful-decorators/dist-types/sortby.d.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * Sort array by a specific element property, its value type must be one of string, number and date
3 | * @param {string | undefined} sortByProperty specify a property from each element that sorting will be based on, undefined means sorty by element itself
4 | * @param {
5 | isDescending: boolean;
6 | sortByPropertyType: string;
7 | } options
8 | * @returns script version
9 | */
10 | export declare function SortBy(sortByProperty: string | symbol | number, options?: {
11 | isDescending: boolean;
12 | type: string;
13 | }): (target: any, propertyKey: string, descriptor?: PropertyDescriptor | undefined) => void;
14 |
--------------------------------------------------------------------------------
/week-12-1/classes/node_modules/helpful-decorators/dist-types/throttle.d.ts:
--------------------------------------------------------------------------------
1 | export declare function throttle(milliseconds?: number, options?: {}): any;
2 |
--------------------------------------------------------------------------------
/week-12-1/classes/node_modules/helpful-decorators/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "helpful-decorators",
3 | "description": "Helpful decorators for typescript projects",
4 | "version": "2.1.0",
5 | "license": "MIT",
6 | "esnext": "dist-src/index.js",
7 | "main": "dist-node/index.js",
8 | "module": "dist-web/index.js",
9 | "types": "dist-types/index.d.ts",
10 | "pika": true,
11 | "sideEffects": false,
12 | "keywords": [
13 | "decorators",
14 | "setTimeout decorator",
15 | "debounce decorator",
16 | "once decorator",
17 | "mixin decorator",
18 | "measure decorator"
19 | ],
20 | "files": [
21 | "dist-*/",
22 | "assets/",
23 | "bin/"
24 | ],
25 | "repository": {
26 | "type": "git",
27 | "url": "https://github.com/NetanelBasal/helpful-decorators"
28 | },
29 | "dependencies": {
30 | "lodash.debounce": "4.0.8",
31 | "lodash.delay": "4.1.1",
32 | "lodash.memoize": "4.1.2",
33 | "lodash.once": "4.1.1",
34 | "lodash.throttle": "4.1.1"
35 | },
36 | "devDependencies": {
37 | "@pika/pack": "^0.3.5",
38 | "@pika/plugin-build-node": "^0.3.14",
39 | "@pika/plugin-build-types": "^0.3.14",
40 | "@pika/plugin-build-web": "^0.3.14",
41 | "@pika/plugin-standard-pkg": "^0.3.14",
42 | "@types/jest": "24.0.11",
43 | "jest": "24.5.0",
44 | "ts-jest": "24.0.0",
45 | "typescript": "3.3.3333"
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/week-12-1/classes/node_modules/lodash.debounce/README.md:
--------------------------------------------------------------------------------
1 | # lodash.debounce v4.0.8
2 |
3 | The [lodash](https://lodash.com/) method `_.debounce` exported as a [Node.js](https://nodejs.org/) module.
4 |
5 | ## Installation
6 |
7 | Using npm:
8 | ```bash
9 | $ {sudo -H} npm i -g npm
10 | $ npm i --save lodash.debounce
11 | ```
12 |
13 | In Node.js:
14 | ```js
15 | var debounce = require('lodash.debounce');
16 | ```
17 |
18 | See the [documentation](https://lodash.com/docs#debounce) or [package source](https://github.com/lodash/lodash/blob/4.0.8-npm-packages/lodash.debounce) for more details.
19 |
--------------------------------------------------------------------------------
/week-12-1/classes/node_modules/lodash.debounce/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "lodash.debounce",
3 | "version": "4.0.8",
4 | "description": "The lodash method `_.debounce` exported as a module.",
5 | "homepage": "https://lodash.com/",
6 | "icon": "https://lodash.com/icon.svg",
7 | "license": "MIT",
8 | "keywords": "lodash-modularized, debounce",
9 | "author": "John-David Dalton (http://allyoucanleet.com/)",
10 | "contributors": [
11 | "John-David Dalton (http://allyoucanleet.com/)",
12 | "Blaine Bublitz (https://github.com/phated)",
13 | "Mathias Bynens (https://mathiasbynens.be/)"
14 | ],
15 | "repository": "lodash/lodash",
16 | "scripts": { "test": "echo \"See https://travis-ci.org/lodash/lodash-cli for testing details.\"" }
17 | }
18 |
--------------------------------------------------------------------------------
/week-12-1/classes/node_modules/lodash.delay/README.md:
--------------------------------------------------------------------------------
1 | # lodash.delay v4.1.1
2 |
3 | The [lodash](https://lodash.com/) method `_.delay` exported as a [Node.js](https://nodejs.org/) module.
4 |
5 | ## Installation
6 |
7 | Using npm:
8 | ```bash
9 | $ {sudo -H} npm i -g npm
10 | $ npm i --save lodash.delay
11 | ```
12 |
13 | In Node.js:
14 | ```js
15 | var delay = require('lodash.delay');
16 | ```
17 |
18 | See the [documentation](https://lodash.com/docs#delay) or [package source](https://github.com/lodash/lodash/blob/4.1.1-npm-packages/lodash.delay) for more details.
19 |
--------------------------------------------------------------------------------
/week-12-1/classes/node_modules/lodash.delay/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "lodash.delay",
3 | "version": "4.1.1",
4 | "description": "The lodash method `_.delay` exported as a module.",
5 | "homepage": "https://lodash.com/",
6 | "icon": "https://lodash.com/icon.svg",
7 | "license": "MIT",
8 | "keywords": "lodash-modularized, delay",
9 | "author": "John-David Dalton (http://allyoucanleet.com/)",
10 | "contributors": [
11 | "John-David Dalton (http://allyoucanleet.com/)",
12 | "Blaine Bublitz (https://github.com/phated)",
13 | "Mathias Bynens (https://mathiasbynens.be/)"
14 | ],
15 | "repository": "lodash/lodash",
16 | "scripts": { "test": "echo \"See https://travis-ci.org/lodash/lodash-cli for testing details.\"" }
17 | }
18 |
--------------------------------------------------------------------------------
/week-12-1/classes/node_modules/lodash.memoize/README.md:
--------------------------------------------------------------------------------
1 | # lodash.memoize v4.1.2
2 |
3 | The [lodash](https://lodash.com/) method `_.memoize` exported as a [Node.js](https://nodejs.org/) module.
4 |
5 | ## Installation
6 |
7 | Using npm:
8 | ```bash
9 | $ {sudo -H} npm i -g npm
10 | $ npm i --save lodash.memoize
11 | ```
12 |
13 | In Node.js:
14 | ```js
15 | var memoize = require('lodash.memoize');
16 | ```
17 |
18 | See the [documentation](https://lodash.com/docs#memoize) or [package source](https://github.com/lodash/lodash/blob/4.1.2-npm-packages/lodash.memoize) for more details.
19 |
--------------------------------------------------------------------------------
/week-12-1/classes/node_modules/lodash.memoize/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "lodash.memoize",
3 | "version": "4.1.2",
4 | "description": "The lodash method `_.memoize` exported as a module.",
5 | "homepage": "https://lodash.com/",
6 | "icon": "https://lodash.com/icon.svg",
7 | "license": "MIT",
8 | "keywords": "lodash-modularized, memoize",
9 | "author": "John-David Dalton (http://allyoucanleet.com/)",
10 | "contributors": [
11 | "John-David Dalton (http://allyoucanleet.com/)",
12 | "Blaine Bublitz (https://github.com/phated)",
13 | "Mathias Bynens (https://mathiasbynens.be/)"
14 | ],
15 | "repository": "lodash/lodash",
16 | "scripts": { "test": "echo \"See https://travis-ci.org/lodash/lodash-cli for testing details.\"" }
17 | }
18 |
--------------------------------------------------------------------------------
/week-12-1/classes/node_modules/lodash.once/README.md:
--------------------------------------------------------------------------------
1 | # lodash.once v4.1.1
2 |
3 | The [lodash](https://lodash.com/) method `_.once` exported as a [Node.js](https://nodejs.org/) module.
4 |
5 | ## Installation
6 |
7 | Using npm:
8 | ```bash
9 | $ {sudo -H} npm i -g npm
10 | $ npm i --save lodash.once
11 | ```
12 |
13 | In Node.js:
14 | ```js
15 | var once = require('lodash.once');
16 | ```
17 |
18 | See the [documentation](https://lodash.com/docs#once) or [package source](https://github.com/lodash/lodash/blob/4.1.1-npm-packages/lodash.once) for more details.
19 |
--------------------------------------------------------------------------------
/week-12-1/classes/node_modules/lodash.once/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "lodash.once",
3 | "version": "4.1.1",
4 | "description": "The lodash method `_.once` exported as a module.",
5 | "homepage": "https://lodash.com/",
6 | "icon": "https://lodash.com/icon.svg",
7 | "license": "MIT",
8 | "keywords": "lodash-modularized, once",
9 | "author": "John-David Dalton (http://allyoucanleet.com/)",
10 | "contributors": [
11 | "John-David Dalton (http://allyoucanleet.com/)",
12 | "Blaine Bublitz (https://github.com/phated)",
13 | "Mathias Bynens (https://mathiasbynens.be/)"
14 | ],
15 | "repository": "lodash/lodash",
16 | "scripts": { "test": "echo \"See https://travis-ci.org/lodash/lodash-cli for testing details.\"" }
17 | }
18 |
--------------------------------------------------------------------------------
/week-12-1/classes/node_modules/lodash.throttle/README.md:
--------------------------------------------------------------------------------
1 | # lodash.throttle v4.1.1
2 |
3 | The [lodash](https://lodash.com/) method `_.throttle` exported as a [Node.js](https://nodejs.org/) module.
4 |
5 | ## Installation
6 |
7 | Using npm:
8 | ```bash
9 | $ {sudo -H} npm i -g npm
10 | $ npm i --save lodash.throttle
11 | ```
12 |
13 | In Node.js:
14 | ```js
15 | var throttle = require('lodash.throttle');
16 | ```
17 |
18 | See the [documentation](https://lodash.com/docs#throttle) or [package source](https://github.com/lodash/lodash/blob/4.1.1-npm-packages/lodash.throttle) for more details.
19 |
--------------------------------------------------------------------------------
/week-12-1/classes/node_modules/lodash.throttle/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "lodash.throttle",
3 | "version": "4.1.1",
4 | "description": "The lodash method `_.throttle` exported as a module.",
5 | "homepage": "https://lodash.com/",
6 | "icon": "https://lodash.com/icon.svg",
7 | "license": "MIT",
8 | "keywords": "lodash-modularized, throttle",
9 | "author": "John-David Dalton (http://allyoucanleet.com/)",
10 | "contributors": [
11 | "John-David Dalton (http://allyoucanleet.com/)",
12 | "Blaine Bublitz (https://github.com/phated)",
13 | "Mathias Bynens (https://mathiasbynens.be/)"
14 | ],
15 | "repository": "lodash/lodash",
16 | "scripts": { "test": "echo \"See https://travis-ci.org/lodash/lodash-cli for testing details.\"" }
17 | }
18 |
--------------------------------------------------------------------------------
/week-12-1/todo-backend/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 |
--------------------------------------------------------------------------------
/week-12-1/todo-backend/build/src/server.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", { value: true });
3 | // src/server.ts
4 | const app_1 = require("./app");
5 | const port = process.env.PORT || 3000;
6 | app_1.app.listen(port, () => console.log(`Example app listening at http://localhost:${port}`));
7 |
--------------------------------------------------------------------------------
/week-12-1/todo-backend/build/src/todos/todo.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", { value: true });
3 |
--------------------------------------------------------------------------------
/week-12-1/todo-backend/build/src/todos/todoService.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", { value: true });
3 | exports.TodoService = void 0;
4 | class TodoService {
5 | get(todoId) {
6 | return {
7 | id: todoId,
8 | title: "mocked todo",
9 | description: "mocked todo",
10 | done: false
11 | };
12 | }
13 | create(todoCreationParams) {
14 | return {
15 | id: "1",
16 | title: "mocked todo",
17 | description: "mocked todo",
18 | done: false
19 | };
20 | }
21 | }
22 | exports.TodoService = TodoService;
23 |
--------------------------------------------------------------------------------
/week-12-1/todo-backend/node-client/core/ApiError.ts:
--------------------------------------------------------------------------------
1 | /* generated using openapi-typescript-codegen -- do no edit */
2 | /* istanbul ignore file */
3 | /* tslint:disable */
4 | /* eslint-disable */
5 | import type { ApiRequestOptions } from './ApiRequestOptions';
6 | import type { ApiResult } from './ApiResult';
7 |
8 | export class ApiError extends Error {
9 | public readonly url: string;
10 | public readonly status: number;
11 | public readonly statusText: string;
12 | public readonly body: any;
13 | public readonly request: ApiRequestOptions;
14 |
15 | constructor(request: ApiRequestOptions, response: ApiResult, message: string) {
16 | super(message);
17 |
18 | this.name = 'ApiError';
19 | this.url = response.url;
20 | this.status = response.status;
21 | this.statusText = response.statusText;
22 | this.body = response.body;
23 | this.request = request;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/week-12-1/todo-backend/node-client/core/ApiRequestOptions.ts:
--------------------------------------------------------------------------------
1 | /* generated using openapi-typescript-codegen -- do no edit */
2 | /* istanbul ignore file */
3 | /* tslint:disable */
4 | /* eslint-disable */
5 | export type ApiRequestOptions = {
6 | readonly method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'OPTIONS' | 'HEAD' | 'PATCH';
7 | readonly url: string;
8 | readonly path?: Record;
9 | readonly cookies?: Record;
10 | readonly headers?: Record;
11 | readonly query?: Record;
12 | readonly formData?: Record;
13 | readonly body?: any;
14 | readonly mediaType?: string;
15 | readonly responseHeader?: string;
16 | readonly errors?: Record;
17 | };
18 |
--------------------------------------------------------------------------------
/week-12-1/todo-backend/node-client/core/ApiResult.ts:
--------------------------------------------------------------------------------
1 | /* generated using openapi-typescript-codegen -- do no edit */
2 | /* istanbul ignore file */
3 | /* tslint:disable */
4 | /* eslint-disable */
5 | export type ApiResult = {
6 | readonly url: string;
7 | readonly ok: boolean;
8 | readonly status: number;
9 | readonly statusText: string;
10 | readonly body: any;
11 | };
12 |
--------------------------------------------------------------------------------
/week-12-1/todo-backend/node-client/core/OpenAPI.ts:
--------------------------------------------------------------------------------
1 | /* generated using openapi-typescript-codegen -- do no edit */
2 | /* istanbul ignore file */
3 | /* tslint:disable */
4 | /* eslint-disable */
5 | import type { ApiRequestOptions } from './ApiRequestOptions';
6 |
7 | type Resolver = (options: ApiRequestOptions) => Promise;
8 | type Headers = Record;
9 |
10 | export type OpenAPIConfig = {
11 | BASE: string;
12 | VERSION: string;
13 | WITH_CREDENTIALS: boolean;
14 | CREDENTIALS: 'include' | 'omit' | 'same-origin';
15 | TOKEN?: string | Resolver | undefined;
16 | USERNAME?: string | Resolver | undefined;
17 | PASSWORD?: string | Resolver | undefined;
18 | HEADERS?: Headers | Resolver | undefined;
19 | ENCODE_PATH?: ((path: string) => string) | undefined;
20 | };
21 |
22 | export const OpenAPI: OpenAPIConfig = {
23 | BASE: '',
24 | VERSION: '1.0.0',
25 | WITH_CREDENTIALS: false,
26 | CREDENTIALS: 'include',
27 | TOKEN: undefined,
28 | USERNAME: undefined,
29 | PASSWORD: undefined,
30 | HEADERS: undefined,
31 | ENCODE_PATH: undefined,
32 | };
33 |
--------------------------------------------------------------------------------
/week-12-1/todo-backend/node-client/index.ts:
--------------------------------------------------------------------------------
1 | /* generated using openapi-typescript-codegen -- do no edit */
2 | /* istanbul ignore file */
3 | /* tslint:disable */
4 | /* eslint-disable */
5 | export { ApiError } from './core/ApiError';
6 | export { CancelablePromise, CancelError } from './core/CancelablePromise';
7 | export { OpenAPI } from './core/OpenAPI';
8 | export type { OpenAPIConfig } from './core/OpenAPI';
9 |
10 | export type { Todo } from './models/Todo';
11 |
12 | export { DefaultService } from './services/DefaultService';
13 |
--------------------------------------------------------------------------------
/week-12-1/todo-backend/node-client/models/Todo.ts:
--------------------------------------------------------------------------------
1 | /* generated using openapi-typescript-codegen -- do no edit */
2 | /* istanbul ignore file */
3 | /* tslint:disable */
4 | /* eslint-disable */
5 |
6 | export type Todo = {
7 | title: string;
8 | description: string;
9 | id: string;
10 | done: boolean;
11 | };
12 |
--------------------------------------------------------------------------------
/week-12-1/todo-backend/node-client/services/DefaultService.ts:
--------------------------------------------------------------------------------
1 | /* generated using openapi-typescript-codegen -- do no edit */
2 | /* istanbul ignore file */
3 | /* tslint:disable */
4 | /* eslint-disable */
5 | import type { Todo } from '../models/Todo';
6 |
7 | import type { CancelablePromise } from '../core/CancelablePromise';
8 | import { OpenAPI } from '../core/OpenAPI';
9 | import { request as __request } from '../core/request';
10 |
11 | export class DefaultService {
12 |
13 | /**
14 | * @param todoId
15 | * @returns Todo Ok
16 | * @throws ApiError
17 | */
18 | public static getTodo(
19 | todoId: string,
20 | ): CancelablePromise {
21 | return __request(OpenAPI, {
22 | method: 'GET',
23 | url: '/todo/{todoId}',
24 | path: {
25 | 'todoId': todoId,
26 | },
27 | });
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/week-12-1/todo-backend/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "todo-backend",
3 | "version": "1.0.0",
4 | "main": "index.js",
5 | "license": "MIT",
6 | "dependencies": {
7 | "express": "^4.18.2",
8 | "openapi-typescript-codegen": "^0.25.0",
9 | "swagger-ui-express": "^5.0.0",
10 | "tsoa": "^5.1.1"
11 | },
12 | "devDependencies": {
13 | "@types/express": "^4.17.19",
14 | "@types/node": "^20.8.4",
15 | "@types/swagger-ui-express": "^4.1.4",
16 | "typescript": "^5.2.2"
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/week-12-1/todo-backend/src/app.ts:
--------------------------------------------------------------------------------
1 | // src/app.ts
2 | import express, {json, urlencoded} from "express";
3 | import { Response as ExResponse, Request as ExRequest } from "express";
4 | import { RegisterRoutes } from "../build/routes";
5 | import swaggerUi from "swagger-ui-express";
6 | export const app = express();
7 |
8 | // Use body parser to read sent json payloads
9 | app.use(
10 | urlencoded({
11 | extended: true,
12 | })
13 | );
14 |
15 | app.use("/docs", swaggerUi.serve, async (_req: ExRequest, res: ExResponse) => {
16 | return res.send(
17 | swaggerUi.generateHTML(await import("../build/swagger.json"))
18 | );
19 | });
20 | app.use(json());
21 |
22 | RegisterRoutes(app);
--------------------------------------------------------------------------------
/week-12-1/todo-backend/src/server.ts:
--------------------------------------------------------------------------------
1 | // src/server.ts
2 | import { app } from "./app";
3 |
4 | const port = process.env.PORT || 3000;
5 |
6 | app.listen(port, () =>
7 | console.log(`Example app listening at http://localhost:${port}`)
8 | );
--------------------------------------------------------------------------------
/week-12-1/todo-backend/src/todos/todo.ts:
--------------------------------------------------------------------------------
1 | export interface Todo{
2 | title:string;
3 | description:string;
4 | id:string;
5 | done:boolean;
6 | }
7 |
--------------------------------------------------------------------------------
/week-12-1/todo-backend/src/todos/todoService.ts:
--------------------------------------------------------------------------------
1 | import { Todo } from "./todo";
2 |
3 | //Pick --> from Todo pick title, description
4 | export type TodoCreationParams = Pick
5 |
6 | export class TodoService {
7 | public get(todoId: string):Todo {
8 | return {
9 | id: todoId,
10 | title: "mocked todo",
11 | description: "mocked todo",
12 | done: false
13 | }
14 | }
15 | public create(todoCreationParams:TodoCreationParams):Todo{
16 | return{
17 | id: "1",
18 | title: "mocked todo",
19 | description: "mocked todo",
20 | done: false
21 | }
22 | }
23 | }
--------------------------------------------------------------------------------
/week-12-1/todo-backend/src/todos/todosController.ts:
--------------------------------------------------------------------------------
1 | import {
2 | Body,
3 | Controller,
4 | Get,
5 | Path,
6 | Post,
7 | Query,
8 | Route,
9 | SuccessResponse,
10 | } from "tsoa";
11 | import {Todo} from "./todo"
12 | import { TodoCreationParams, TodoService } from "./todoService";
13 |
14 | @Route("todo")
15 | export class TodoController extends Controller{
16 |
17 | /**
18 | * This is the controller for creating the Todos
19 | */
20 |
21 | @Get("{todoId}")
22 | public async getTodo(
23 | @Path() todoId: string
24 | ): Promise {
25 | let todoService = new TodoService();
26 | return todoService.get(todoId)
27 | }
28 | }
--------------------------------------------------------------------------------
/week-12-1/todo-backend/tsoa.json:
--------------------------------------------------------------------------------
1 | {
2 | "entryFile": "src/app.ts",
3 | "noImplicitAdditionalProperties": "throw-on-extras",
4 | "controllerPathGlobs": ["src/**/*Controller.ts"],
5 | "spec": {
6 | "outputDirectory": "build",
7 | "specVersion": 3
8 | },
9 | "routes": {
10 | "routesDir": "build"
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/week-16-master/part-1-create-simple-server/client/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | dist
3 |
--------------------------------------------------------------------------------
/week-16-master/part-1-create-simple-server/client/index.ts:
--------------------------------------------------------------------------------
1 | import { Chain } from "./zeus";
2 |
3 | const chain = Chain("http://localhost:4000/graphql", {
4 | headers: {
5 | authorization: "Bearer 123123",
6 | "Content-Type": "application/json"
7 | }
8 | });
9 |
10 | async function send() {
11 | try {
12 | const response = await chain("mutation")({
13 | createUser: [{
14 | input: {
15 | email: "harkirat1@gmail.com",
16 | firstname: "harkirat",
17 | lastname: "singh"
18 | }
19 | }, {
20 | id: true,
21 | email: true
22 | }]
23 | })
24 | console.log(response.createUser)
25 | } catch(e) {
26 | console.log(e);
27 | }
28 | }
29 |
30 | send();
31 |
--------------------------------------------------------------------------------
/week-16-master/part-1-create-simple-server/client/package-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "client",
3 | "version": "1.0.0",
4 | "lockfileVersion": 3,
5 | "requires": true,
6 | "packages": {
7 | "": {
8 | "name": "client",
9 | "version": "1.0.0",
10 | "license": "ISC"
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/week-16-master/part-1-create-simple-server/client/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "client",
3 | "version": "1.0.0",
4 | "main": "index.js",
5 | "scripts": {
6 | "test": "echo \"Error: no test specified\" && exit 1"
7 | },
8 | "keywords": [],
9 | "author": "",
10 | "license": "ISC",
11 | "description": ""
12 | }
13 |
--------------------------------------------------------------------------------
/week-16-master/part-1-create-simple-server/client/zeus/const.ts:
--------------------------------------------------------------------------------
1 | /* eslint-disable */
2 |
3 | export const AllTypesProps: Record = {
4 | Query:{
5 | getUser:{
6 |
7 | }
8 | },
9 | CreateUserInput:{
10 |
11 | },
12 | Mutation:{
13 | createUser:{
14 | input:"CreateUserInput"
15 | }
16 | }
17 | }
18 |
19 | export const ReturnTypes: Record = {
20 | User:{
21 | id:"ID",
22 | email:"String",
23 | firstname:"String",
24 | lastname:"String"
25 | },
26 | Query:{
27 | getUser:"User"
28 | },
29 | Mutation:{
30 | createUser:"User"
31 | }
32 | }
33 |
34 | export const Ops = {
35 | query: "Query" as const,
36 | mutation: "Mutation" as const
37 | }
--------------------------------------------------------------------------------
/week-16-master/part-1-create-simple-server/client2/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 |
--------------------------------------------------------------------------------
/week-16-master/part-1-create-simple-server/client2/client/zeus/const.ts:
--------------------------------------------------------------------------------
1 | /* eslint-disable */
2 |
3 | export const AllTypesProps: Record = {
4 | Query:{
5 | getUser:{
6 |
7 | }
8 | },
9 | CreateUserInput:{
10 |
11 | },
12 | Mutation:{
13 | createUser:{
14 | input:"CreateUserInput"
15 | }
16 | }
17 | }
18 |
19 | export const ReturnTypes: Record = {
20 | User:{
21 | id:"ID",
22 | email:"String",
23 | firstname:"String",
24 | lastname:"String"
25 | },
26 | Query:{
27 | getUser:"User"
28 | },
29 | Mutation:{
30 | createUser:"User"
31 | }
32 | }
33 |
34 | export const Ops = {
35 | query: "Query" as const,
36 | mutation: "Mutation" as const
37 | }
--------------------------------------------------------------------------------
/week-16-master/part-1-create-simple-server/client2/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "client2",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "zeus": "npx graphql-zeus http://localhost:4000/graphql ./client"
8 | },
9 | "keywords": [],
10 | "author": "",
11 | "license": "ISC",
12 | "dependencies": {
13 | "graphql-zeus": "^5.3.1"
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/week-16-master/part-1-create-simple-server/server/.gitignore:
--------------------------------------------------------------------------------
1 | dist
2 | node_modules
3 |
--------------------------------------------------------------------------------
/week-16-master/part-1-create-simple-server/server/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "week-16",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "zeus": "npx graphql-zeus http://localhost:4000/graphql ./client"
8 | },
9 | "keywords": [],
10 | "author": "",
11 | "license": "ISC",
12 | "dependencies": {
13 | "@types/express": "^4.17.17",
14 | "express": "^4.18.2",
15 | "express-graphql": "^0.12.0",
16 | "graphql": "^15.8.0"
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/week-16-master/part-1-create-simple-server/server/schema.gql:
--------------------------------------------------------------------------------
1 | type User {
2 | id: ID!
3 | email: String!
4 | firstname: String!
5 | lastname: String!
6 | }
7 |
8 | type Query {
9 | getUser(id: ID!): User
10 | }
11 |
12 | input CreateUserInput {
13 | email: String!
14 | firstname: String!
15 | lastname: String!
16 | }
17 |
18 | type Mutation {
19 | createUser(input: CreateUserInput!): User!
20 | }
21 |
22 |
--------------------------------------------------------------------------------
/week-16-master/part-1-create-simple-server/server/src/index.ts:
--------------------------------------------------------------------------------
1 | import express from 'express';
2 | import { graphqlHTTP } from 'express-graphql';
3 | import { buildSchema } from 'graphql';
4 | import * as path from "path";
5 |
6 | const fs = require('fs');
7 | const schemaString = fs.readFileSync(path.join(__dirname, './schema.gql'), 'utf8');
8 | const schema = buildSchema(schemaString);
9 |
10 | const authMiddleware = (req, res, next) => {
11 | req.authHeader = req.headers.authorization;
12 | next();
13 | }
14 |
15 | const root = {
16 | getUser: ({ id }, req) => {
17 | console.log(req.authHeader);
18 | // mongoose/prisma logic to get the user
19 | if (id === '1') {
20 | return { id: '1', email: 'john.doe@example.com', firstname: 'John', lastname: 'Doe' };
21 | }
22 | return null;
23 | },
24 | createUser: ({ input }, req) => {
25 | console.log(req.authHeader);
26 | // mongoose/prisma logic to store the user
27 | return { id: '2', ...input };
28 | }
29 | };
30 |
31 | const app = express();
32 |
33 | app.use('/graphql', authMiddleware, graphqlHTTP({
34 | schema: schema,
35 | rootValue: root,
36 | graphiql: true,
37 | }));
38 |
39 | const PORT = 4000;
40 | app.listen(PORT, () => {
41 | console.log(`Running a GraphQL API server at http://localhost:${PORT}/graphql`);
42 | });
43 |
--------------------------------------------------------------------------------
/week-16-master/part-1-create-simple-server/server/src/schema.gql:
--------------------------------------------------------------------------------
1 | type User {
2 | id: ID!
3 | email: String!
4 | firstname: String!
5 | lastname: String!
6 | }
7 |
8 | type Query {
9 | getUser(id: ID!): User
10 | }
11 |
12 | input CreateUserInput {
13 | email: String!
14 | firstname: String!
15 | lastname: String!
16 | }
17 |
18 | type Mutation {
19 | createUser(input: CreateUserInput!): User!
20 | }
21 |
22 |
--------------------------------------------------------------------------------
/week-16-master/part-2-hasura-dockerfile/README.md:
--------------------------------------------------------------------------------
1 |
2 | docker-compose up
3 | npx hasura-cli console
4 | psql -h localhost -p 4446 -U user -d reef_dev
5 |
6 | You wil notice there is a race between pg and hasura
7 |
--------------------------------------------------------------------------------
/week-16-master/part-2-hasura-dockerfile/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: "3.8"
2 |
3 | services:
4 | postgres:
5 | image: postgres:15.0-alpine
6 | ports:
7 | - 4446:5432
8 | volumes:
9 | - data:/var/lib/postgresql1/data
10 | environment:
11 | POSTGRES_DB: reef_dev
12 | POSTGRES_PASSWORD: pass
13 | POSTGRES_USER: user
14 |
15 | hasura:
16 | image: hasura/graphql-engine:v2.18.0.cli-migrations-v3
17 | ports:
18 | - 8112:8080
19 | depends_on:
20 | - postgres
21 | environment:
22 | HASURA_GRAPHQL_DATABASE_URL: postgres://user:pass@postgres/reef_dev
23 | HASURA_GRAPHQL_DEV_MODE: "true"
24 | HASURA_GRAPHQL_ADMIN_SECRET: myadminsecretkey
25 |
26 | volumes:
27 | data:
28 |
29 |
--------------------------------------------------------------------------------
/week-16-master/part-2-hasura-dockerfile/hasura/config.yaml:
--------------------------------------------------------------------------------
1 | version: 3
2 | endpoint: http://localhost:8112
3 | metadata_directory: metadata
4 | admin_secret: myadminsecretkey
5 |
--------------------------------------------------------------------------------
/week-16-master/part-3-hasura-dockerfile/README.md:
--------------------------------------------------------------------------------
1 |
2 | docker-compose up
3 | npx hasura-cli console
4 | -inside hasura folder
5 | psql -h localhost -p 4446 -U user -d reef_dev
6 |
7 | You wil notice there is a race between pg and hasura
8 |
--------------------------------------------------------------------------------
/week-16-master/part-3-hasura-dockerfile/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: "3.8"
2 |
3 | services:
4 | postgres:
5 | image: postgres:15.0-alpine
6 | ports:
7 | - 4446:5432
8 | volumes:
9 | - data:/var/lib/postgresql1/data
10 | restart: always
11 | environment:
12 | POSTGRES_DB: reef_dev
13 | POSTGRES_PASSWORD: pass
14 | POSTGRES_USER: user
15 | healthcheck:
16 | test: pg_isready --username=user --dbname=reef_dev --quiet
17 | interval: 15s
18 | timeout: 5s
19 | hasura:
20 | restart: always
21 | image: hasura/graphql-engine:v2.18.0.cli-migrations-v3
22 | ports:
23 | - 8112:8080
24 | depends_on:
25 | - postgres
26 | environment:
27 | HASURA_GRAPHQL_DATABASE_URL: postgres://user:pass@postgres/reef_dev
28 | HASURA_GRAPHQL_DEV_MODE: "true"
29 | HASURA_GRAPHQL_ADMIN_SECRET: myadminsecretkey
30 |
31 | volumes:
32 | data:
33 |
34 |
--------------------------------------------------------------------------------
/week-16-master/part-3-hasura-dockerfile/hasura/config.yaml:
--------------------------------------------------------------------------------
1 | version: 3
2 | endpoint: http://localhost:8112
3 | metadata_directory: metadata
4 | admin_secret: myadminsecretkey
5 |
--------------------------------------------------------------------------------
/week-16/week-16-master/part-1-create-simple-server/client/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | dist
3 |
--------------------------------------------------------------------------------
/week-16/week-16-master/part-1-create-simple-server/client/index.ts:
--------------------------------------------------------------------------------
1 | import { Chain } from "./zeus";
2 |
3 | const chain = Chain("http://localhost:4000/graphql");
4 |
5 | async function send() {
6 | try {
7 | const response = await chain("mutation")({
8 | createUser: [{
9 | input: {
10 | email: "harkirat1@gmail.com",
11 | firstname: "harkirat",
12 | lastname: "singh"
13 | }
14 | }, {
15 | id: true,
16 | email: true
17 | }]
18 | })
19 | console.log(response)
20 | } catch(e) {
21 | console.log(e);
22 | }
23 | }
24 |
25 | send();
26 |
--------------------------------------------------------------------------------
/week-16/week-16-master/part-1-create-simple-server/client/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "client",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "keywords": [],
10 | "author": "",
11 | "license": "ISC"
12 | }
13 |
--------------------------------------------------------------------------------
/week-16/week-16-master/part-1-create-simple-server/client/zeus/const.ts:
--------------------------------------------------------------------------------
1 | /* eslint-disable */
2 |
3 | export const AllTypesProps: Record = {
4 | Query:{
5 | getUser:{
6 |
7 | }
8 | },
9 | CreateUserInput:{
10 |
11 | },
12 | Mutation:{
13 | createUser:{
14 | input:"CreateUserInput"
15 | }
16 | }
17 | }
18 |
19 | export const ReturnTypes: Record = {
20 | User:{
21 | id:"ID",
22 | email:"String",
23 | firstname:"String",
24 | lastname:"String"
25 | },
26 | Query:{
27 | getUser:"User"
28 | },
29 | Mutation:{
30 | createUser:"User"
31 | }
32 | }
33 |
34 | export const Ops = {
35 | query: "Query" as const,
36 | mutation: "Mutation" as const
37 | }
--------------------------------------------------------------------------------
/week-16/week-16-master/part-1-create-simple-server/server/.gitignore:
--------------------------------------------------------------------------------
1 | dist
2 | node_modules
3 |
--------------------------------------------------------------------------------
/week-16/week-16-master/part-1-create-simple-server/server/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "week-16",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "zeus": "npx graphql-zeus http://localhost:4000/graphql ./client"
8 | },
9 | "keywords": [],
10 | "author": "",
11 | "license": "ISC",
12 | "dependencies": {
13 | "@types/express": "^4.17.17",
14 | "express": "^4.18.2",
15 | "express-graphql": "^0.12.0",
16 | "graphql": "^15.8.0"
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/week-16/week-16-master/part-1-create-simple-server/server/schema.gql:
--------------------------------------------------------------------------------
1 | type User {
2 | id: ID!
3 | email: String!
4 | firstname: String!
5 | lastname: String!
6 | }
7 |
8 | type Query {
9 | getUser(id: ID!): User
10 | }
11 |
12 | input CreateUserInput {
13 | email: String!
14 | firstname: String!
15 | lastname: String!
16 | }
17 |
18 | type Mutation {
19 | createUser(input: CreateUserInput!): User!
20 | }
21 |
22 |
--------------------------------------------------------------------------------
/week-16/week-16-master/part-1-create-simple-server/server/src/index.ts:
--------------------------------------------------------------------------------
1 | import express from 'express';
2 | import { graphqlHTTP } from 'express-graphql';
3 | import { buildSchema } from 'graphql';
4 | import * as path from "path";
5 |
6 | const fs = require('fs');
7 | const schemaString = fs.readFileSync(path.join(__dirname, './schema.gql'), 'utf8');
8 | const schema = buildSchema(schemaString);
9 |
10 | const authMiddleware = (req, res, next) => {
11 | req.authHeader = req.headers.authorization;
12 | next();
13 | }
14 |
15 | const root = {
16 | getUser: ({ id }, req) => {
17 | console.log(req.authHeader);
18 |
19 | // mongoose/prisma logic to get the user
20 | if (id === '1') {
21 | return { id: '1', email: 'john.doe@example.com', firstname: 'John', lastname: 'Doe' };
22 | }
23 | return null;
24 | },
25 | createUser: ({ input }, req) => {
26 | console.log(req.authHeader);
27 | // mongoose/prisma logic to store the user
28 | return { id: '2', ...input };
29 | }
30 | };
31 |
32 | const app = express();
33 |
34 | app.get("/healthcheck", (req: any, res: any) => {
35 | res.json({"msg": "hi"});
36 | })
37 | app.use('/graphql', graphqlHTTP({
38 | schema: schema,
39 | rootValue: root,
40 | graphiql: true,
41 | }));
42 |
43 | const PORT = 4000;
44 | app.listen(PORT, () => {
45 | console.log(`Running a GraphQL API server at http://localhost:${PORT}/graphql`);
46 | });
47 |
--------------------------------------------------------------------------------
/week-16/week-16-master/part-1-create-simple-server/server/src/schema.gql:
--------------------------------------------------------------------------------
1 | type User {
2 | id: ID!
3 | email: String!
4 | firstname: String!
5 | lastname: String!
6 | }
7 |
8 | type Query {
9 | getUser(id: ID!): User
10 | }
11 |
12 | input CreateUserInput {
13 | email: String!
14 | firstname: String!
15 | lastname: String!
16 | }
17 |
18 | type Mutation {
19 | createUser(input: CreateUserInput!): User!
20 | }
21 |
22 |
--------------------------------------------------------------------------------
/week-16/week-16-master/part-2-hasura-dockerfile/README.md:
--------------------------------------------------------------------------------
1 |
2 | docker-compose up
3 | npx hasura-cli console
4 | psql -h localhost -p 4446 -U user -d reef_dev
5 |
6 | You wil notice there is a race between pg and hasura
7 |
--------------------------------------------------------------------------------
/week-16/week-16-master/part-2-hasura-dockerfile/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: "3.8"
2 |
3 | services:
4 | postgres:
5 | image: postgres:15.0-alpine
6 | ports:
7 | - 4446:5432
8 | volumes:
9 | - data:/var/lib/postgresql1/data
10 | environment:
11 | POSTGRES_DB: reef_dev
12 | POSTGRES_PASSWORD: pass
13 | POSTGRES_USER: user
14 |
15 | hasura:
16 | image: hasura/graphql-engine:v2.18.0.cli-migrations-v3
17 | ports:
18 | - 8112:8080
19 | depends_on:
20 | - postgres
21 | environment:
22 | HASURA_GRAPHQL_DATABASE_URL: postgres://user:pass@postgres/reef_dev
23 | HASURA_GRAPHQL_DEV_MODE: "true"
24 | HASURA_GRAPHQL_ADMIN_SECRET: myadminsecretkey
25 |
26 | volumes:
27 | data:
28 |
29 |
--------------------------------------------------------------------------------
/week-16/week-16-master/part-2-hasura-dockerfile/hasura/config.yaml:
--------------------------------------------------------------------------------
1 | version: 3
2 | endpoint: http://localhost:8112
3 | metadata_directory: metadata
4 | admin_secret: myadminsecretkey
5 |
--------------------------------------------------------------------------------
/week-16/week-16-master/part-2-hasura-dockerfile/package-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "part-2-hasura-dockerfile",
3 | "lockfileVersion": 3,
4 | "requires": true,
5 | "packages": {}
6 | }
7 |
--------------------------------------------------------------------------------
/week-16/week-16-master/part-3-hasura-dockerfile/README.md:
--------------------------------------------------------------------------------
1 |
2 | docker-compose up
3 | npx hasura-cli console
4 | psql -h localhost -p 4446 -U user -d reef_dev
5 | - To connect hasura with postgres server
6 | 
7 | You wil notice there is a race between pg and hasura
8 |
--------------------------------------------------------------------------------
/week-16/week-16-master/part-3-hasura-dockerfile/docker-compose.yml:
--------------------------------------------------------------------------------
1 | version: "3.8"
2 |
3 | services:
4 | postgres:
5 | image: postgres:15.0-alpine
6 | ports:
7 | - 4446:5432
8 | volumes:
9 | - data:/var/lib/postgresql1/data
10 | restart: always
11 | environment:
12 | POSTGRES_DB: reef_dev
13 | POSTGRES_PASSWORD: pass
14 | POSTGRES_USER: user
15 | healthcheck:
16 | test: pg_isready --username=user --dbname=reef_dev --quiet
17 | interval: 15s
18 | timeout: 5s
19 | hasura:
20 | restart: always
21 | image: hasura/graphql-engine:v2.18.0.cli-migrations-v3
22 | ports:
23 | - 8112:8080
24 | depends_on:
25 | - postgres
26 | environment:
27 | HASURA_GRAPHQL_DATABASE_URL: postgres://user:pass@postgres/reef_dev
28 | HASURA_GRAPHQL_DEV_MODE: "true"
29 | HASURA_GRAPHQL_ADMIN_SECRET: myadminsecretkey
30 |
31 | volumes:
32 | data:
33 |
34 |
--------------------------------------------------------------------------------
/week-16/week-16-master/part-3-hasura-dockerfile/hasura/config.yaml:
--------------------------------------------------------------------------------
1 | version: 3
2 | endpoint: http://localhost:8112
3 | metadata_directory: metadata
4 | admin_secret: myadminsecretkey
5 |
--------------------------------------------------------------------------------
/week-16/week-16-master/part-3-hasura-dockerfile/image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ajaydeep123/100xdevsCohort/20b7c0ac5444177a23e8b3bf298adb3c3be87057/week-16/week-16-master/part-3-hasura-dockerfile/image.png
--------------------------------------------------------------------------------
/week-8-repo/client/.eslintrc.cjs:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | root: true,
3 | env: { browser: true, es2020: true },
4 | extends: [
5 | 'eslint:recommended',
6 | 'plugin:@typescript-eslint/recommended',
7 | 'plugin:react-hooks/recommended',
8 | ],
9 | ignorePatterns: ['dist', '.eslintrc.cjs'],
10 | parser: '@typescript-eslint/parser',
11 | plugins: ['react-refresh'],
12 | rules: {
13 | 'react-refresh/only-export-components': [
14 | 'warn',
15 | { allowConstantExport: true },
16 | ],
17 | },
18 | }
19 |
--------------------------------------------------------------------------------
/week-8-repo/client/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 | pnpm-debug.log*
8 | lerna-debug.log*
9 |
10 | node_modules
11 | dist
12 | dist-ssr
13 | *.local
14 |
15 | # Editor directories and files
16 | .vscode/*
17 | !.vscode/extensions.json
18 | .idea
19 | .DS_Store
20 | *.suo
21 | *.ntvs*
22 | *.njsproj
23 | *.sln
24 | *.sw?
25 |
--------------------------------------------------------------------------------
/week-8-repo/client/README.md:
--------------------------------------------------------------------------------
1 | # React + TypeScript + Vite
2 |
3 | This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4 |
5 | Currently, two official plugins are available:
6 |
7 | - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
8 | - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
9 |
10 | ## Expanding the ESLint configuration
11 |
12 | If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:
13 |
14 | - Configure the top-level `parserOptions` property like this:
15 |
16 | ```js
17 | parserOptions: {
18 | ecmaVersion: 'latest',
19 | sourceType: 'module',
20 | project: ['./tsconfig.json', './tsconfig.node.json'],
21 | tsconfigRootDir: __dirname,
22 | },
23 | ```
24 |
25 | - Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
26 | - Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
27 | - Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list
28 |
--------------------------------------------------------------------------------
/week-8-repo/client/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Vite + React + TS
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/week-8-repo/client/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "assignment-2-solution",
3 | "private": true,
4 | "version": "0.0.0",
5 | "type": "module",
6 | "scripts": {
7 | "dev": "vite",
8 | "build": "tsc && vite build",
9 | "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
10 | "preview": "vite preview"
11 | },
12 | "dependencies": {
13 | "@ajaydeep968/common": "^1.0.2",
14 | "react": "^18.2.0",
15 | "react-dom": "^18.2.0",
16 | "react-router-dom": "^6.14.2",
17 | "recoil": "^0.7.7",
18 | "swr": "^2.2.0"
19 | },
20 | "devDependencies": {
21 | "@types/react": "^18.2.15",
22 | "@types/react-dom": "^18.2.7",
23 | "@typescript-eslint/eslint-plugin": "^6.0.0",
24 | "@typescript-eslint/parser": "^6.0.0",
25 | "@vitejs/plugin-react": "^4.0.3",
26 | "eslint": "^8.45.0",
27 | "eslint-plugin-react-hooks": "^4.6.0",
28 | "eslint-plugin-react-refresh": "^0.4.3",
29 | "typescript": "^5.0.2",
30 | "vite": "^4.4.5"
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/week-8-repo/client/public/vite.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/week-8-repo/client/src/App.css:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ajaydeep123/100xdevsCohort/20b7c0ac5444177a23e8b3bf298adb3c3be87057/week-8-repo/client/src/App.css
--------------------------------------------------------------------------------
/week-8-repo/client/src/Components/Login.tsx:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react';
2 | import {Link} from 'react-router-dom';
3 |
4 | const Login = () => {
5 | const [username, setUsername] = useState('');
6 | const [password, setPassword] = useState('');
7 |
8 | const handleLogin = async () => {
9 | const response = await fetch('http://localhost:3000/auth/login', {
10 | method: 'POST',
11 | headers: { 'Content-Type': 'application/json' },
12 | body: JSON.stringify({ username, password })
13 | });
14 | // Todo: Create a type for the response that you get back from the server
15 | const data = await response.json();
16 | if (data.token) {
17 | localStorage.setItem("token", data.token)
18 | window.location = "/todos";
19 | } else {
20 | alert("invalid credentials");
21 | }
22 | };
23 |
24 | return (
25 |
34 | );
35 | };
36 |
37 | export default Login;
38 |
--------------------------------------------------------------------------------
/week-8-repo/client/src/index.css:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ajaydeep123/100xdevsCohort/20b7c0ac5444177a23e8b3bf298adb3c3be87057/week-8-repo/client/src/index.css
--------------------------------------------------------------------------------
/week-8-repo/client/src/main.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import ReactDOM from 'react-dom/client'
3 | import App from './App.tsx'
4 | import './index.css'
5 |
6 | ReactDOM.createRoot(document.getElementById('root')!).render(
7 |
8 |
9 | ,
10 | )
11 |
--------------------------------------------------------------------------------
/week-8-repo/client/src/store/authState.ts:
--------------------------------------------------------------------------------
1 | import { atom } from 'recoil';
2 |
3 | export const authState = atom({
4 | key: 'authState',
5 | default: { token: null, username: null },
6 | });
--------------------------------------------------------------------------------
/week-8-repo/client/src/vite-env.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 |
--------------------------------------------------------------------------------
/week-8-repo/client/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "ES2020",
4 | "useDefineForClassFields": true,
5 | "lib": ["ES2020", "DOM", "DOM.Iterable"],
6 | "module": "ESNext",
7 | "skipLibCheck": true,
8 |
9 | /* Bundler mode */
10 | "moduleResolution": "bundler",
11 | "allowImportingTsExtensions": true,
12 | "resolveJsonModule": true,
13 | "isolatedModules": true,
14 | "noEmit": true,
15 | "jsx": "react-jsx",
16 |
17 | /* Linting */
18 | "strict": true,
19 | "noUnusedLocals": true,
20 | "noUnusedParameters": true,
21 | "noFallthroughCasesInSwitch": true
22 | },
23 | "include": ["src"],
24 | "references": [{ "path": "./tsconfig.node.json" }]
25 | }
26 |
--------------------------------------------------------------------------------
/week-8-repo/client/tsconfig.node.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "composite": true,
4 | "skipLibCheck": true,
5 | "module": "ESNext",
6 | "moduleResolution": "bundler",
7 | "allowSyntheticDefaultImports": true
8 | },
9 | "include": ["vite.config.ts"]
10 | }
11 |
--------------------------------------------------------------------------------
/week-8-repo/client/vite.config.ts:
--------------------------------------------------------------------------------
1 | import { defineConfig } from 'vite'
2 | import react from '@vitejs/plugin-react'
3 |
4 | // https://vitejs.dev/config/
5 | export default defineConfig({
6 | plugins: [react()],
7 | })
8 |
--------------------------------------------------------------------------------
/week-8-repo/common/.npmignore:
--------------------------------------------------------------------------------
1 | src
2 |
--------------------------------------------------------------------------------
/week-8-repo/common/dist/index.d.ts:
--------------------------------------------------------------------------------
1 | import { z } from "zod";
2 | export declare const signupInput: z.ZodObject<{
3 | username: z.ZodString;
4 | password: z.ZodString;
5 | }, "strip", z.ZodTypeAny, {
6 | username: string;
7 | password: string;
8 | }, {
9 | username: string;
10 | password: string;
11 | }>;
12 | export type SignupParams = z.infer;
13 |
--------------------------------------------------------------------------------
/week-8-repo/common/dist/index.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", { value: true });
3 | exports.signupInput = void 0;
4 | const zod_1 = require("zod");
5 | exports.signupInput = zod_1.z.object({
6 | username: zod_1.z.string(),
7 | password: zod_1.z.string(),
8 | });
9 |
--------------------------------------------------------------------------------
/week-8-repo/common/node_modules/.package-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@ajaydeep968/common",
3 | "version": "1.0.2",
4 | "lockfileVersion": 3,
5 | "requires": true,
6 | "packages": {
7 | "node_modules/@ajaydeep968/common": {
8 | "version": "1.0.2",
9 | "resolved": "https://registry.npmjs.org/@ajaydeep968/common/-/common-1.0.2.tgz",
10 | "integrity": "sha512-Us5MVh/UqSkd3YakrIoLgdb5o5qX1E+6gawqpIc5i2XUmHp2WAtOAsL5nlzSuSlQ6s0s3nCXeCC4nKI3J/drGw==",
11 | "dependencies": {
12 | "zod": "^3.22.4"
13 | }
14 | },
15 | "node_modules/zod": {
16 | "version": "3.22.4",
17 | "resolved": "https://registry.npmjs.org/zod/-/zod-3.22.4.tgz",
18 | "integrity": "sha512-iC+8Io04lddc+mVqQ9AZ7OQ2MrUKGN+oIQyq1vemgt46jwCwLfhq7/pwnBnNXXXZb8VTVLKwp9EDkx+ryxIWmg==",
19 | "funding": {
20 | "url": "https://github.com/sponsors/colinhacks"
21 | }
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/week-8-repo/common/node_modules/@ajaydeep968/common/dist/index.d.ts:
--------------------------------------------------------------------------------
1 | import { z } from "zod";
2 | export declare const signupInput: z.ZodObject<{
3 | username: z.ZodString;
4 | password: z.ZodString;
5 | }, "strip", z.ZodTypeAny, {
6 | username: string;
7 | password: string;
8 | }, {
9 | username: string;
10 | password: string;
11 | }>;
12 | export type SignupParams = z.infer;
13 |
--------------------------------------------------------------------------------
/week-8-repo/common/node_modules/@ajaydeep968/common/dist/index.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", { value: true });
3 | exports.signupInput = void 0;
4 | const zod_1 = require("zod");
5 | exports.signupInput = zod_1.z.object({
6 | username: zod_1.z.string(),
7 | password: zod_1.z.string(),
8 | });
9 |
--------------------------------------------------------------------------------
/week-8-repo/common/node_modules/@ajaydeep968/common/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@ajaydeep968/common",
3 | "version": "1.0.2",
4 | "description": "",
5 | "main": "dist/index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "keywords": [],
10 | "author": "",
11 | "license": "ISC",
12 | "dependencies": {
13 | "zod": "^3.22.4"
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/week-8-repo/common/node_modules/zod/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Colin McDonnell
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/week-8-repo/common/node_modules/zod/index.d.ts:
--------------------------------------------------------------------------------
1 | export * from "./lib";
2 | export as namespace Zod;
3 |
--------------------------------------------------------------------------------
/week-8-repo/common/node_modules/zod/lib/__tests__/Mocker.d.ts:
--------------------------------------------------------------------------------
1 | export declare class Mocker {
2 | pick: (...args: any[]) => any;
3 | get string(): string;
4 | get number(): number;
5 | get bigint(): bigint;
6 | get boolean(): boolean;
7 | get date(): Date;
8 | get symbol(): symbol;
9 | get null(): null;
10 | get undefined(): undefined;
11 | get stringOptional(): any;
12 | get stringNullable(): any;
13 | get numberOptional(): any;
14 | get numberNullable(): any;
15 | get booleanOptional(): any;
16 | get booleanNullable(): any;
17 | }
18 |
--------------------------------------------------------------------------------
/week-8-repo/common/node_modules/zod/lib/benchmarks/discriminatedUnion.d.ts:
--------------------------------------------------------------------------------
1 | import Benchmark from "benchmark";
2 | declare const _default: {
3 | suites: Benchmark.Suite[];
4 | };
5 | export default _default;
6 |
--------------------------------------------------------------------------------
/week-8-repo/common/node_modules/zod/lib/benchmarks/index.d.ts:
--------------------------------------------------------------------------------
1 | export {};
2 |
--------------------------------------------------------------------------------
/week-8-repo/common/node_modules/zod/lib/benchmarks/object.d.ts:
--------------------------------------------------------------------------------
1 | import Benchmark from "benchmark";
2 | declare const _default: {
3 | suites: Benchmark.Suite[];
4 | };
5 | export default _default;
6 |
--------------------------------------------------------------------------------
/week-8-repo/common/node_modules/zod/lib/benchmarks/primitives.d.ts:
--------------------------------------------------------------------------------
1 | import Benchmark from "benchmark";
2 | declare const _default: {
3 | suites: Benchmark.Suite[];
4 | };
5 | export default _default;
6 |
--------------------------------------------------------------------------------
/week-8-repo/common/node_modules/zod/lib/benchmarks/realworld.d.ts:
--------------------------------------------------------------------------------
1 | import Benchmark from "benchmark";
2 | declare const _default: {
3 | suites: Benchmark.Suite[];
4 | };
5 | export default _default;
6 |
--------------------------------------------------------------------------------
/week-8-repo/common/node_modules/zod/lib/benchmarks/string.d.ts:
--------------------------------------------------------------------------------
1 | import Benchmark from "benchmark";
2 | declare const _default: {
3 | suites: Benchmark.Suite[];
4 | };
5 | export default _default;
6 |
--------------------------------------------------------------------------------
/week-8-repo/common/node_modules/zod/lib/benchmarks/union.d.ts:
--------------------------------------------------------------------------------
1 | import Benchmark from "benchmark";
2 | declare const _default: {
3 | suites: Benchmark.Suite[];
4 | };
5 | export default _default;
6 |
--------------------------------------------------------------------------------
/week-8-repo/common/node_modules/zod/lib/errors.d.ts:
--------------------------------------------------------------------------------
1 | import defaultErrorMap from "./locales/en";
2 | import type { ZodErrorMap } from "./ZodError";
3 | export { defaultErrorMap };
4 | export declare function setErrorMap(map: ZodErrorMap): void;
5 | export declare function getErrorMap(): ZodErrorMap;
6 |
--------------------------------------------------------------------------------
/week-8-repo/common/node_modules/zod/lib/errors.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
4 | };
5 | Object.defineProperty(exports, "__esModule", { value: true });
6 | exports.getErrorMap = exports.setErrorMap = exports.defaultErrorMap = void 0;
7 | const en_1 = __importDefault(require("./locales/en"));
8 | exports.defaultErrorMap = en_1.default;
9 | let overrideErrorMap = en_1.default;
10 | function setErrorMap(map) {
11 | overrideErrorMap = map;
12 | }
13 | exports.setErrorMap = setErrorMap;
14 | function getErrorMap() {
15 | return overrideErrorMap;
16 | }
17 | exports.getErrorMap = getErrorMap;
18 |
--------------------------------------------------------------------------------
/week-8-repo/common/node_modules/zod/lib/external.d.ts:
--------------------------------------------------------------------------------
1 | export * from "./errors";
2 | export * from "./helpers/parseUtil";
3 | export * from "./helpers/typeAliases";
4 | export * from "./helpers/util";
5 | export * from "./types";
6 | export * from "./ZodError";
7 |
--------------------------------------------------------------------------------
/week-8-repo/common/node_modules/zod/lib/external.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3 | if (k2 === undefined) k2 = k;
4 | Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5 | }) : (function(o, m, k, k2) {
6 | if (k2 === undefined) k2 = k;
7 | o[k2] = m[k];
8 | }));
9 | var __exportStar = (this && this.__exportStar) || function(m, exports) {
10 | for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11 | };
12 | Object.defineProperty(exports, "__esModule", { value: true });
13 | __exportStar(require("./errors"), exports);
14 | __exportStar(require("./helpers/parseUtil"), exports);
15 | __exportStar(require("./helpers/typeAliases"), exports);
16 | __exportStar(require("./helpers/util"), exports);
17 | __exportStar(require("./types"), exports);
18 | __exportStar(require("./ZodError"), exports);
19 |
--------------------------------------------------------------------------------
/week-8-repo/common/node_modules/zod/lib/helpers/enumUtil.d.ts:
--------------------------------------------------------------------------------
1 | export declare namespace enumUtil {
2 | type UnionToIntersectionFn = (T extends unknown ? (k: () => T) => void : never) extends (k: infer Intersection) => void ? Intersection : never;
3 | type GetUnionLast = UnionToIntersectionFn extends () => infer Last ? Last : never;
4 | type UnionToTuple = [T] extends [never] ? Tuple : UnionToTuple>, [GetUnionLast, ...Tuple]>;
5 | type CastToStringTuple = T extends [string, ...string[]] ? T : never;
6 | export type UnionToTupleString = CastToStringTuple>;
7 | export {};
8 | }
9 |
--------------------------------------------------------------------------------
/week-8-repo/common/node_modules/zod/lib/helpers/enumUtil.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", { value: true });
3 |
--------------------------------------------------------------------------------
/week-8-repo/common/node_modules/zod/lib/helpers/errorUtil.d.ts:
--------------------------------------------------------------------------------
1 | export declare namespace errorUtil {
2 | type ErrMessage = string | {
3 | message?: string;
4 | };
5 | const errToObj: (message?: ErrMessage | undefined) => {
6 | message?: string | undefined;
7 | };
8 | const toString: (message?: ErrMessage | undefined) => string | undefined;
9 | }
10 |
--------------------------------------------------------------------------------
/week-8-repo/common/node_modules/zod/lib/helpers/errorUtil.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", { value: true });
3 | exports.errorUtil = void 0;
4 | var errorUtil;
5 | (function (errorUtil) {
6 | errorUtil.errToObj = (message) => typeof message === "string" ? { message } : message || {};
7 | errorUtil.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
8 | })(errorUtil = exports.errorUtil || (exports.errorUtil = {}));
9 |
--------------------------------------------------------------------------------
/week-8-repo/common/node_modules/zod/lib/helpers/partialUtil.d.ts:
--------------------------------------------------------------------------------
1 | import type { ZodArray, ZodNullable, ZodObject, ZodOptional, ZodRawShape, ZodTuple, ZodTupleItems, ZodTypeAny } from "../index";
2 | export declare namespace partialUtil {
3 | type DeepPartial = T extends ZodObject ? ZodObject<{
4 | [k in keyof T["shape"]]: ZodOptional>;
5 | }, T["_def"]["unknownKeys"], T["_def"]["catchall"]> : T extends ZodArray ? ZodArray, Card> : T extends ZodOptional ? ZodOptional> : T extends ZodNullable ? ZodNullable> : T extends ZodTuple ? {
6 | [k in keyof Items]: Items[k] extends ZodTypeAny ? DeepPartial : never;
7 | } extends infer PI ? PI extends ZodTupleItems ? ZodTuple : never : never : T;
8 | }
9 |
--------------------------------------------------------------------------------
/week-8-repo/common/node_modules/zod/lib/helpers/partialUtil.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", { value: true });
3 |
--------------------------------------------------------------------------------
/week-8-repo/common/node_modules/zod/lib/helpers/typeAliases.d.ts:
--------------------------------------------------------------------------------
1 | export declare type Primitive = string | number | symbol | bigint | boolean | null | undefined;
2 | export declare type Scalars = Primitive | Primitive[];
3 |
--------------------------------------------------------------------------------
/week-8-repo/common/node_modules/zod/lib/helpers/typeAliases.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", { value: true });
3 |
--------------------------------------------------------------------------------
/week-8-repo/common/node_modules/zod/lib/index.d.ts:
--------------------------------------------------------------------------------
1 | import * as z from "./external";
2 | export * from "./external";
3 | export { z };
4 | export default z;
5 |
--------------------------------------------------------------------------------
/week-8-repo/common/node_modules/zod/lib/index.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3 | if (k2 === undefined) k2 = k;
4 | Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5 | }) : (function(o, m, k, k2) {
6 | if (k2 === undefined) k2 = k;
7 | o[k2] = m[k];
8 | }));
9 | var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10 | Object.defineProperty(o, "default", { enumerable: true, value: v });
11 | }) : function(o, v) {
12 | o["default"] = v;
13 | });
14 | var __importStar = (this && this.__importStar) || function (mod) {
15 | if (mod && mod.__esModule) return mod;
16 | var result = {};
17 | if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18 | __setModuleDefault(result, mod);
19 | return result;
20 | };
21 | var __exportStar = (this && this.__exportStar) || function(m, exports) {
22 | for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
23 | };
24 | Object.defineProperty(exports, "__esModule", { value: true });
25 | exports.z = void 0;
26 | const z = __importStar(require("./external"));
27 | exports.z = z;
28 | __exportStar(require("./external"), exports);
29 | exports.default = z;
30 |
--------------------------------------------------------------------------------
/week-8-repo/common/node_modules/zod/lib/locales/en.d.ts:
--------------------------------------------------------------------------------
1 | import { ZodErrorMap } from "../ZodError";
2 | declare const errorMap: ZodErrorMap;
3 | export default errorMap;
4 |
--------------------------------------------------------------------------------
/week-8-repo/common/package-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@ajaydeep968/common",
3 | "version": "1.0.2",
4 | "lockfileVersion": 3,
5 | "requires": true,
6 | "packages": {
7 | "": {
8 | "name": "@ajaydeep968/common",
9 | "version": "1.0.2",
10 | "license": "ISC",
11 | "dependencies": {
12 | "@ajaydeep968/common": "^1.0.2",
13 | "zod": "^3.22.4"
14 | }
15 | },
16 | "node_modules/@ajaydeep968/common": {
17 | "version": "1.0.2",
18 | "resolved": "https://registry.npmjs.org/@ajaydeep968/common/-/common-1.0.2.tgz",
19 | "integrity": "sha512-Us5MVh/UqSkd3YakrIoLgdb5o5qX1E+6gawqpIc5i2XUmHp2WAtOAsL5nlzSuSlQ6s0s3nCXeCC4nKI3J/drGw==",
20 | "dependencies": {
21 | "zod": "^3.22.4"
22 | }
23 | },
24 | "node_modules/zod": {
25 | "version": "3.22.4",
26 | "resolved": "https://registry.npmjs.org/zod/-/zod-3.22.4.tgz",
27 | "integrity": "sha512-iC+8Io04lddc+mVqQ9AZ7OQ2MrUKGN+oIQyq1vemgt46jwCwLfhq7/pwnBnNXXXZb8VTVLKwp9EDkx+ryxIWmg==",
28 | "funding": {
29 | "url": "https://github.com/sponsors/colinhacks"
30 | }
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/week-8-repo/common/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@ajaydeep968/common",
3 | "version": "1.0.2",
4 | "description": "",
5 | "main": "dist/index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "keywords": [],
10 | "author": "",
11 | "license": "ISC",
12 | "dependencies": {
13 | "@ajaydeep968/common": "^1.0.2",
14 | "zod": "^3.22.4"
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/week-8-repo/common/src/index.ts:
--------------------------------------------------------------------------------
1 | import {z} from "zod";
2 |
3 | export const signupInput = z.object({
4 | username: z.string(),
5 | password: z.string(),
6 | })
7 |
8 | export type SignupParams = z.infer
--------------------------------------------------------------------------------
/week-8-repo/server/.gitignore:
--------------------------------------------------------------------------------
1 | dist
2 | .idea/
3 | node_modules
4 |
--------------------------------------------------------------------------------
/week-8-repo/server/db/index.ts:
--------------------------------------------------------------------------------
1 | import mongoose from "mongoose";
2 |
3 | const userSchema = new mongoose.Schema({
4 | username: String,
5 | password: String,
6 | });
7 |
8 | const todoSchema = new mongoose.Schema({
9 | title: String,
10 | description: String,
11 | done: Boolean,
12 | userId: String,
13 | });
14 |
15 | export const User = mongoose.model('User', userSchema);
16 | export const Todo = mongoose.model('Todo', todoSchema);
17 |
--------------------------------------------------------------------------------
/week-8-repo/server/index.ts:
--------------------------------------------------------------------------------
1 |
2 | import express from "express";
3 | import mongoose from "mongoose";
4 | const app = express();
5 |
6 | const port = 3000;
7 | import authRoutes from "./routes/auth";
8 | import todoRoutes from "./routes/todo";
9 | import cors from "cors";
10 |
11 | app.use(cors());
12 | app.use(express.json());
13 | app.use("/auth", authRoutes);
14 | app.use("/todo", todoRoutes);
15 |
16 | app.listen(port, () => {
17 | console.log(`Example app listening at http://localhost:${port}`)
18 | })
19 |
20 | mongoose.connect('mongodb://127.0.0.1:27017/courses', { dbName: "courses" }).then(()=>{console.log("mongodb connected")});
21 |
--------------------------------------------------------------------------------
/week-8-repo/server/middleware/index.ts:
--------------------------------------------------------------------------------
1 | import jwt from 'jsonwebtoken';
2 | export const SECRET = 'SECr3t'; // This should be in an environment variable in a real application
3 | import { Request, Response, NextFunction } from "express";
4 |
5 | export const authenticateJwt = (req: Request, res: Response, next: NextFunction) => {
6 | const authHeader = req.headers.authorization;
7 |
8 | if (authHeader) {
9 | const token = authHeader.split(' ')[1];
10 | jwt.verify(token, SECRET, (err, payload) => {
11 | if (err) {
12 | return res.sendStatus(403);
13 | }
14 | if (!payload) {
15 | return res.sendStatus(403);
16 | }
17 | if (typeof payload === "string") {
18 | return res.sendStatus(403);
19 | }
20 |
21 | req.headers["userId"] = payload.id;
22 | next();
23 | });
24 | } else {
25 | res.sendStatus(401);
26 | }
27 | };
28 |
29 |
30 |
--------------------------------------------------------------------------------
/week-8-repo/server/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "assignment-1",
3 | "version": "1.0.0",
4 | "description": "Convert this from JS to typescript.",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "keywords": [],
10 | "author": "",
11 | "license": "ISC",
12 | "dependencies": {
13 | "@ajaydeep968/common": "^1.0.2",
14 | "@types/cors": "^2.8.13",
15 | "@types/express": "^4.17.17",
16 | "@types/jsonwebtoken": "^9.0.2",
17 | "@types/mongoose": "^5.11.97",
18 | "cors": "^2.8.5",
19 | "express": "^4.18.2",
20 | "jsonwebtoken": "^9.0.1",
21 | "mongoose": "^7.4.1",
22 | "pm2": "^5.3.0",
23 | "zod": "^3.22.4"
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/week-8-repo/server/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
4 | "module": "commonjs", /* Specify what module code is generated. */
5 | "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
6 | "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
7 | "strict": true, /* Enable all strict type-checking options. */
8 | "skipLibCheck": true, /* Skip type checking all .d.ts files. */
9 | "outDir": "dist"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/week-8.1/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ajaydeep123/100xdevsCohort/20b7c0ac5444177a23e8b3bf298adb3c3be87057/week-8.1/.DS_Store
--------------------------------------------------------------------------------
/week-8.1/client/.eslintrc.cjs:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | root: true,
3 | env: { browser: true, es2020: true },
4 | extends: [
5 | 'eslint:recommended',
6 | 'plugin:@typescript-eslint/recommended',
7 | 'plugin:react-hooks/recommended',
8 | ],
9 | ignorePatterns: ['dist', '.eslintrc.cjs'],
10 | parser: '@typescript-eslint/parser',
11 | plugins: ['react-refresh'],
12 | rules: {
13 | 'react-refresh/only-export-components': [
14 | 'warn',
15 | { allowConstantExport: true },
16 | ],
17 | },
18 | }
19 |
--------------------------------------------------------------------------------
/week-8.1/client/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 | pnpm-debug.log*
8 | lerna-debug.log*
9 |
10 | node_modules
11 | dist
12 | dist-ssr
13 | *.local
14 |
15 | # Editor directories and files
16 | .vscode/*
17 | !.vscode/extensions.json
18 | .idea
19 | .DS_Store
20 | *.suo
21 | *.ntvs*
22 | *.njsproj
23 | *.sln
24 | *.sw?
25 |
--------------------------------------------------------------------------------
/week-8.1/client/README.md:
--------------------------------------------------------------------------------
1 | # React + TypeScript + Vite
2 |
3 | This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4 |
5 | Currently, two official plugins are available:
6 |
7 | - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
8 | - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
9 |
10 | ## Expanding the ESLint configuration
11 |
12 | If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:
13 |
14 | - Configure the top-level `parserOptions` property like this:
15 |
16 | ```js
17 | parserOptions: {
18 | ecmaVersion: 'latest',
19 | sourceType: 'module',
20 | project: ['./tsconfig.json', './tsconfig.node.json'],
21 | tsconfigRootDir: __dirname,
22 | },
23 | ```
24 |
25 | - Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
26 | - Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
27 | - Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list
28 |
--------------------------------------------------------------------------------
/week-8.1/client/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Vite + React + TS
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/week-8.1/client/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "assignment-2-solution",
3 | "private": true,
4 | "version": "0.0.0",
5 | "type": "module",
6 | "scripts": {
7 | "dev": "vite",
8 | "build": "tsc && vite build",
9 | "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
10 | "preview": "vite preview"
11 | },
12 | "dependencies": {
13 | "@100xdevs/common": "^1.0.1",
14 | "react": "^18.2.0",
15 | "react-dom": "^18.2.0",
16 | "react-router-dom": "^6.14.2",
17 | "recoil": "^0.7.7",
18 | "swr": "^2.2.0"
19 | },
20 | "devDependencies": {
21 | "@types/react": "^18.2.15",
22 | "@types/react-dom": "^18.2.7",
23 | "@typescript-eslint/eslint-plugin": "^6.0.0",
24 | "@typescript-eslint/parser": "^6.0.0",
25 | "@vitejs/plugin-react": "^4.0.3",
26 | "eslint": "^8.45.0",
27 | "eslint-plugin-react-hooks": "^4.6.0",
28 | "eslint-plugin-react-refresh": "^0.4.3",
29 | "typescript": "^5.0.2",
30 | "vite": "^4.4.5"
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/week-8.1/client/public/vite.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/week-8.1/client/src/App.css:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ajaydeep123/100xdevsCohort/20b7c0ac5444177a23e8b3bf298adb3c3be87057/week-8.1/client/src/App.css
--------------------------------------------------------------------------------
/week-8.1/client/src/Components/Login.tsx:
--------------------------------------------------------------------------------
1 | import React, { useState } from 'react';
2 | import {Link} from 'react-router-dom';
3 |
4 | const Login = () => {
5 | const [username, setUsername] = useState('');
6 | const [password, setPassword] = useState('');
7 |
8 | const handleLogin = async () => {
9 | const response = await fetch('http://localhost:3000/auth/login', {
10 | method: 'POST',
11 | headers: { 'Content-Type': 'application/json' },
12 | body: JSON.stringify({ username, password })
13 | });
14 | // Todo: Create a type for the response that you get back from the server
15 | const data = await response.json();
16 | if (data.token) {
17 | localStorage.setItem("token", data.token)
18 | window.location = "/todos";
19 | } else {
20 | alert("invalid credentials");
21 | }
22 | };
23 |
24 | return (
25 |
34 | );
35 | };
36 |
37 | export default Login;
38 |
--------------------------------------------------------------------------------
/week-8.1/client/src/index.css:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ajaydeep123/100xdevsCohort/20b7c0ac5444177a23e8b3bf298adb3c3be87057/week-8.1/client/src/index.css
--------------------------------------------------------------------------------
/week-8.1/client/src/main.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react'
2 | import ReactDOM from 'react-dom/client'
3 | import App from './App.tsx'
4 | import './index.css'
5 |
6 | ReactDOM.createRoot(document.getElementById('root')!).render(
7 |
8 |
9 | ,
10 | )
11 |
--------------------------------------------------------------------------------
/week-8.1/client/src/store/authState.ts:
--------------------------------------------------------------------------------
1 | import { atom } from 'recoil';
2 |
3 | export const authState = atom({
4 | key: 'authState',
5 | default: { token: null, username: null },
6 | });
--------------------------------------------------------------------------------
/week-8.1/client/src/vite-env.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 |
--------------------------------------------------------------------------------
/week-8.1/client/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "ES2020",
4 | "useDefineForClassFields": true,
5 | "lib": ["ES2020", "DOM", "DOM.Iterable"],
6 | "module": "ESNext",
7 | "skipLibCheck": true,
8 |
9 | /* Bundler mode */
10 | "moduleResolution": "bundler",
11 | "allowImportingTsExtensions": true,
12 | "resolveJsonModule": true,
13 | "isolatedModules": true,
14 | "noEmit": true,
15 | "jsx": "react-jsx",
16 |
17 | /* Linting */
18 | "strict": true,
19 | "noUnusedLocals": true,
20 | "noUnusedParameters": true,
21 | "noFallthroughCasesInSwitch": true
22 | },
23 | "include": ["src"],
24 | "references": [{ "path": "./tsconfig.node.json" }]
25 | }
26 |
--------------------------------------------------------------------------------
/week-8.1/client/tsconfig.node.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "composite": true,
4 | "skipLibCheck": true,
5 | "module": "ESNext",
6 | "moduleResolution": "bundler",
7 | "allowSyntheticDefaultImports": true
8 | },
9 | "include": ["vite.config.ts"]
10 | }
11 |
--------------------------------------------------------------------------------
/week-8.1/client/vite.config.ts:
--------------------------------------------------------------------------------
1 | import { defineConfig } from 'vite'
2 | import react from '@vitejs/plugin-react'
3 |
4 | // https://vitejs.dev/config/
5 | export default defineConfig({
6 | plugins: [react()],
7 | })
8 |
--------------------------------------------------------------------------------
/week-8.1/common/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ajaydeep123/100xdevsCohort/20b7c0ac5444177a23e8b3bf298adb3c3be87057/week-8.1/common/.DS_Store
--------------------------------------------------------------------------------
/week-8.1/common/.npmignore:
--------------------------------------------------------------------------------
1 | src
2 |
--------------------------------------------------------------------------------
/week-8.1/common/dist/index.d.ts:
--------------------------------------------------------------------------------
1 | import { z } from "zod";
2 | export declare const signupInput: z.ZodObject<{
3 | username: z.ZodString;
4 | password: z.ZodString;
5 | }, "strip", z.ZodTypeAny, {
6 | username: string;
7 | password: string;
8 | }, {
9 | username: string;
10 | password: string;
11 | }>;
12 | export type SignupParams = z.infer;
13 |
--------------------------------------------------------------------------------
/week-8.1/common/dist/index.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", { value: true });
3 | exports.signupInput = void 0;
4 | const zod_1 = require("zod");
5 | exports.signupInput = zod_1.z.object({
6 | username: zod_1.z.string(),
7 | password: zod_1.z.string()
8 | });
9 | console.log("hi there");
10 |
--------------------------------------------------------------------------------
/week-8.1/common/node_modules/.package-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "common",
3 | "version": "1.0.0",
4 | "lockfileVersion": 2,
5 | "requires": true,
6 | "packages": {
7 | "node_modules/zod": {
8 | "version": "3.21.4",
9 | "resolved": "https://registry.npmjs.org/zod/-/zod-3.21.4.tgz",
10 | "integrity": "sha512-m46AKbrzKVzOzs/DZgVnG5H55N1sv1M8qZU3A8RIKbs3mrACDNeIOeilDymVb2HdmP8uwshOCF4uJ8uM9rCqJw==",
11 | "funding": {
12 | "url": "https://github.com/sponsors/colinhacks"
13 | }
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/week-8.1/common/node_modules/zod/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Colin McDonnell
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/week-8.1/common/node_modules/zod/index.d.ts:
--------------------------------------------------------------------------------
1 | export * from "./lib";
2 | export as namespace Zod;
3 |
--------------------------------------------------------------------------------
/week-8.1/common/node_modules/zod/lib/__tests__/Mocker.d.ts:
--------------------------------------------------------------------------------
1 | export declare class Mocker {
2 | pick: (...args: any[]) => any;
3 | get string(): string;
4 | get number(): number;
5 | get bigint(): bigint;
6 | get boolean(): boolean;
7 | get date(): Date;
8 | get symbol(): symbol;
9 | get null(): null;
10 | get undefined(): undefined;
11 | get stringOptional(): any;
12 | get stringNullable(): any;
13 | get numberOptional(): any;
14 | get numberNullable(): any;
15 | get booleanOptional(): any;
16 | get booleanNullable(): any;
17 | }
18 |
--------------------------------------------------------------------------------
/week-8.1/common/node_modules/zod/lib/benchmarks/discriminatedUnion.d.ts:
--------------------------------------------------------------------------------
1 | import Benchmark from "benchmark";
2 | declare const _default: {
3 | suites: Benchmark.Suite[];
4 | };
5 | export default _default;
6 |
--------------------------------------------------------------------------------
/week-8.1/common/node_modules/zod/lib/benchmarks/index.d.ts:
--------------------------------------------------------------------------------
1 | export {};
2 |
--------------------------------------------------------------------------------
/week-8.1/common/node_modules/zod/lib/benchmarks/object.d.ts:
--------------------------------------------------------------------------------
1 | import Benchmark from "benchmark";
2 | declare const _default: {
3 | suites: Benchmark.Suite[];
4 | };
5 | export default _default;
6 |
--------------------------------------------------------------------------------
/week-8.1/common/node_modules/zod/lib/benchmarks/primitives.d.ts:
--------------------------------------------------------------------------------
1 | import Benchmark from "benchmark";
2 | declare const _default: {
3 | suites: Benchmark.Suite[];
4 | };
5 | export default _default;
6 |
--------------------------------------------------------------------------------
/week-8.1/common/node_modules/zod/lib/benchmarks/realworld.d.ts:
--------------------------------------------------------------------------------
1 | import Benchmark from "benchmark";
2 | declare const _default: {
3 | suites: Benchmark.Suite[];
4 | };
5 | export default _default;
6 |
--------------------------------------------------------------------------------
/week-8.1/common/node_modules/zod/lib/benchmarks/string.d.ts:
--------------------------------------------------------------------------------
1 | import Benchmark from "benchmark";
2 | declare const _default: {
3 | suites: Benchmark.Suite[];
4 | };
5 | export default _default;
6 |
--------------------------------------------------------------------------------
/week-8.1/common/node_modules/zod/lib/benchmarks/union.d.ts:
--------------------------------------------------------------------------------
1 | import Benchmark from "benchmark";
2 | declare const _default: {
3 | suites: Benchmark.Suite[];
4 | };
5 | export default _default;
6 |
--------------------------------------------------------------------------------
/week-8.1/common/node_modules/zod/lib/errors.d.ts:
--------------------------------------------------------------------------------
1 | import defaultErrorMap from "./locales/en";
2 | import type { ZodErrorMap } from "./ZodError";
3 | export { defaultErrorMap };
4 | export declare function setErrorMap(map: ZodErrorMap): void;
5 | export declare function getErrorMap(): ZodErrorMap;
6 |
--------------------------------------------------------------------------------
/week-8.1/common/node_modules/zod/lib/errors.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
4 | };
5 | Object.defineProperty(exports, "__esModule", { value: true });
6 | exports.getErrorMap = exports.setErrorMap = exports.defaultErrorMap = void 0;
7 | const en_1 = __importDefault(require("./locales/en"));
8 | exports.defaultErrorMap = en_1.default;
9 | let overrideErrorMap = en_1.default;
10 | function setErrorMap(map) {
11 | overrideErrorMap = map;
12 | }
13 | exports.setErrorMap = setErrorMap;
14 | function getErrorMap() {
15 | return overrideErrorMap;
16 | }
17 | exports.getErrorMap = getErrorMap;
18 |
--------------------------------------------------------------------------------
/week-8.1/common/node_modules/zod/lib/external.d.ts:
--------------------------------------------------------------------------------
1 | export * from "./errors";
2 | export * from "./helpers/parseUtil";
3 | export * from "./helpers/typeAliases";
4 | export * from "./helpers/util";
5 | export * from "./types";
6 | export * from "./ZodError";
7 |
--------------------------------------------------------------------------------
/week-8.1/common/node_modules/zod/lib/external.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3 | if (k2 === undefined) k2 = k;
4 | Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5 | }) : (function(o, m, k, k2) {
6 | if (k2 === undefined) k2 = k;
7 | o[k2] = m[k];
8 | }));
9 | var __exportStar = (this && this.__exportStar) || function(m, exports) {
10 | for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11 | };
12 | Object.defineProperty(exports, "__esModule", { value: true });
13 | __exportStar(require("./errors"), exports);
14 | __exportStar(require("./helpers/parseUtil"), exports);
15 | __exportStar(require("./helpers/typeAliases"), exports);
16 | __exportStar(require("./helpers/util"), exports);
17 | __exportStar(require("./types"), exports);
18 | __exportStar(require("./ZodError"), exports);
19 |
--------------------------------------------------------------------------------
/week-8.1/common/node_modules/zod/lib/helpers/enumUtil.d.ts:
--------------------------------------------------------------------------------
1 | export declare namespace enumUtil {
2 | type UnionToIntersectionFn = (T extends unknown ? (k: () => T) => void : never) extends (k: infer Intersection) => void ? Intersection : never;
3 | type GetUnionLast = UnionToIntersectionFn extends () => infer Last ? Last : never;
4 | type UnionToTuple = [T] extends [never] ? Tuple : UnionToTuple>, [GetUnionLast, ...Tuple]>;
5 | type CastToStringTuple = T extends [string, ...string[]] ? T : never;
6 | export type UnionToTupleString = CastToStringTuple>;
7 | export {};
8 | }
9 |
--------------------------------------------------------------------------------
/week-8.1/common/node_modules/zod/lib/helpers/enumUtil.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", { value: true });
3 |
--------------------------------------------------------------------------------
/week-8.1/common/node_modules/zod/lib/helpers/errorUtil.d.ts:
--------------------------------------------------------------------------------
1 | export declare namespace errorUtil {
2 | type ErrMessage = string | {
3 | message?: string;
4 | };
5 | const errToObj: (message?: ErrMessage | undefined) => {
6 | message?: string | undefined;
7 | };
8 | const toString: (message?: ErrMessage | undefined) => string | undefined;
9 | }
10 |
--------------------------------------------------------------------------------
/week-8.1/common/node_modules/zod/lib/helpers/errorUtil.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", { value: true });
3 | exports.errorUtil = void 0;
4 | var errorUtil;
5 | (function (errorUtil) {
6 | errorUtil.errToObj = (message) => typeof message === "string" ? { message } : message || {};
7 | errorUtil.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
8 | })(errorUtil = exports.errorUtil || (exports.errorUtil = {}));
9 |
--------------------------------------------------------------------------------
/week-8.1/common/node_modules/zod/lib/helpers/partialUtil.d.ts:
--------------------------------------------------------------------------------
1 | import type { ZodArray, ZodNullable, ZodObject, ZodOptional, ZodRawShape, ZodTuple, ZodTupleItems, ZodTypeAny } from "../index";
2 | export declare namespace partialUtil {
3 | type DeepPartial = T extends ZodObject ? ZodObject<{
4 | [k in keyof T["shape"]]: ZodOptional>;
5 | }, T["_def"]["unknownKeys"], T["_def"]["catchall"]> : T extends ZodArray ? ZodArray, Card> : T extends ZodOptional ? ZodOptional> : T extends ZodNullable ? ZodNullable> : T extends ZodTuple ? {
6 | [k in keyof Items]: Items[k] extends ZodTypeAny ? DeepPartial : never;
7 | } extends infer PI ? PI extends ZodTupleItems ? ZodTuple : never : never : T;
8 | }
9 |
--------------------------------------------------------------------------------
/week-8.1/common/node_modules/zod/lib/helpers/partialUtil.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", { value: true });
3 |
--------------------------------------------------------------------------------
/week-8.1/common/node_modules/zod/lib/helpers/typeAliases.d.ts:
--------------------------------------------------------------------------------
1 | export declare type Primitive = string | number | symbol | bigint | boolean | null | undefined;
2 | export declare type Scalars = Primitive | Primitive[];
3 |
--------------------------------------------------------------------------------
/week-8.1/common/node_modules/zod/lib/helpers/typeAliases.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | Object.defineProperty(exports, "__esModule", { value: true });
3 |
--------------------------------------------------------------------------------
/week-8.1/common/node_modules/zod/lib/index.d.ts:
--------------------------------------------------------------------------------
1 | import * as z from "./external";
2 | export * from "./external";
3 | export { z };
4 | export default z;
5 |
--------------------------------------------------------------------------------
/week-8.1/common/node_modules/zod/lib/index.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3 | if (k2 === undefined) k2 = k;
4 | Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5 | }) : (function(o, m, k, k2) {
6 | if (k2 === undefined) k2 = k;
7 | o[k2] = m[k];
8 | }));
9 | var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10 | Object.defineProperty(o, "default", { enumerable: true, value: v });
11 | }) : function(o, v) {
12 | o["default"] = v;
13 | });
14 | var __importStar = (this && this.__importStar) || function (mod) {
15 | if (mod && mod.__esModule) return mod;
16 | var result = {};
17 | if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18 | __setModuleDefault(result, mod);
19 | return result;
20 | };
21 | var __exportStar = (this && this.__exportStar) || function(m, exports) {
22 | for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
23 | };
24 | Object.defineProperty(exports, "__esModule", { value: true });
25 | exports.z = void 0;
26 | const z = __importStar(require("./external"));
27 | exports.z = z;
28 | __exportStar(require("./external"), exports);
29 | exports.default = z;
30 |
--------------------------------------------------------------------------------
/week-8.1/common/node_modules/zod/lib/locales/en.d.ts:
--------------------------------------------------------------------------------
1 | import { ZodErrorMap } from "../ZodError";
2 | declare const errorMap: ZodErrorMap;
3 | export default errorMap;
4 |
--------------------------------------------------------------------------------
/week-8.1/common/package-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "common",
3 | "version": "1.0.0",
4 | "lockfileVersion": 2,
5 | "requires": true,
6 | "packages": {
7 | "": {
8 | "name": "common",
9 | "version": "1.0.0",
10 | "license": "ISC",
11 | "dependencies": {
12 | "zod": "^3.21.4"
13 | }
14 | },
15 | "node_modules/zod": {
16 | "version": "3.21.4",
17 | "resolved": "https://registry.npmjs.org/zod/-/zod-3.21.4.tgz",
18 | "integrity": "sha512-m46AKbrzKVzOzs/DZgVnG5H55N1sv1M8qZU3A8RIKbs3mrACDNeIOeilDymVb2HdmP8uwshOCF4uJ8uM9rCqJw==",
19 | "funding": {
20 | "url": "https://github.com/sponsors/colinhacks"
21 | }
22 | }
23 | },
24 | "dependencies": {
25 | "zod": {
26 | "version": "3.21.4",
27 | "resolved": "https://registry.npmjs.org/zod/-/zod-3.21.4.tgz",
28 | "integrity": "sha512-m46AKbrzKVzOzs/DZgVnG5H55N1sv1M8qZU3A8RIKbs3mrACDNeIOeilDymVb2HdmP8uwshOCF4uJ8uM9rCqJw=="
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/week-8.1/common/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@100xdevs/common",
3 | "version": "1.0.2",
4 | "description": "",
5 | "main": "dist/index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "keywords": [],
10 | "author": "",
11 | "license": "ISC",
12 | "dependencies": {
13 | "zod": "^3.21.4"
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/week-8.1/common/src/index.ts:
--------------------------------------------------------------------------------
1 | import { z } from "zod";
2 | export const signupInput = z.object({
3 | username: z.string(),
4 | password: z.string()
5 | })
6 | console.log("hi there");
7 |
8 | export type SignupParams = z.infer;
9 |
--------------------------------------------------------------------------------
/week-8.1/package-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "week-8-repo-master",
3 | "lockfileVersion": 3,
4 | "requires": true,
5 | "packages": {}
6 | }
7 |
--------------------------------------------------------------------------------
/week-8.1/server/.gitignore:
--------------------------------------------------------------------------------
1 | dist
2 | .idea/
3 | node_modules
4 |
--------------------------------------------------------------------------------
/week-8.1/server/db/index.ts:
--------------------------------------------------------------------------------
1 | import mongoose from "mongoose";
2 |
3 | const userSchema = new mongoose.Schema({
4 | username: String,
5 | password: String,
6 | });
7 |
8 | const todoSchema = new mongoose.Schema({
9 | title: String,
10 | description: String,
11 | done: Boolean,
12 | userId: String,
13 | });
14 |
15 | export const User = mongoose.model('User', userSchema);
16 | export const Todo = mongoose.model('Todo', todoSchema);
17 |
--------------------------------------------------------------------------------
/week-8.1/server/index.ts:
--------------------------------------------------------------------------------
1 |
2 | import express from "express";
3 | import mongoose from "mongoose";
4 | const app = express();
5 |
6 | const port = 3000;
7 | import authRoutes from "./routes/auth";
8 | import todoRoutes from "./routes/todo";
9 | import cors from "cors";
10 |
11 | app.use(cors());
12 | app.use(express.json());
13 | app.use("/auth", authRoutes);
14 | app.use("/todo", todoRoutes);
15 |
16 | app.listen(port, () => {
17 | console.log(`Example app listening at http://localhost:${port}`)
18 | })
19 |
20 | mongoose.connect('mongodb://localhost:27017/courses', { dbName: "courses" });
21 |
--------------------------------------------------------------------------------
/week-8.1/server/middleware/index.ts:
--------------------------------------------------------------------------------
1 | import jwt from 'jsonwebtoken';
2 | export const SECRET = 'SECr3t'; // This should be in an environment variable in a real application
3 | import { Request, Response, NextFunction } from "express";
4 |
5 | export const authenticateJwt = (req: Request, res: Response, next: NextFunction) => {
6 | const authHeader = req.headers.authorization;
7 |
8 | if (authHeader) {
9 | const token = authHeader.split(' ')[1];
10 | jwt.verify(token, SECRET, (err, payload) => {
11 | if (err) {
12 | return res.sendStatus(403);
13 | }
14 | if (!payload) {
15 | return res.sendStatus(403);
16 | }
17 | if (typeof payload === "string") {
18 | return res.sendStatus(403);
19 | }
20 |
21 | req.headers["userId"] = payload.id;
22 | next();
23 | });
24 | } else {
25 | res.sendStatus(401);
26 | }
27 | };
28 |
29 |
30 |
--------------------------------------------------------------------------------
/week-8.1/server/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "assignment-1",
3 | "version": "1.0.0",
4 | "description": "Convert this from JS to typescript.",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "keywords": [],
10 | "author": "",
11 | "license": "ISC",
12 | "dependencies": {
13 | "@100xdevs/common": "^1.0.2",
14 | "@types/cors": "^2.8.13",
15 | "@types/express": "^4.17.17",
16 | "@types/jsonwebtoken": "^9.0.2",
17 | "@types/mongoose": "^5.11.97",
18 | "cors": "^2.8.5",
19 | "express": "^4.18.2",
20 | "jsonwebtoken": "^9.0.1",
21 | "mongoose": "^7.4.1",
22 | "zod": "^3.21.4"
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/week-8.1/server/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
4 | "module": "commonjs", /* Specify what module code is generated. */
5 | "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
6 | "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
7 | "strict": true, /* Enable all strict type-checking options. */
8 | "skipLibCheck": true, /* Skip type checking all .d.ts files. */
9 | "outDir": "dist"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/week-8/index.ts:
--------------------------------------------------------------------------------
1 | /* type NumberArr = number[];
2 |
3 | function getFirstElem(arr:NumberArr):number{
4 | return arr[0];
5 | }
6 |
7 | let ans = getFirstElem([1,2,3]);
8 | console.log(ans);
9 | */
10 |
11 | /*
12 | type User = {
13 | name: string,
14 | age: number
15 | }
16 |
17 | function getFirstItem (arr:T[]){
18 | return arr[0];
19 | }
20 |
21 | let a = getFirstItem([1,2,3]);
22 | let b = getFirstItem(["AJAY", "deep", "Singh"]);
23 |
24 | let c= getFirstItem([{
25 | name:"ajaydeep",
26 | age:24
27 | },{name:"ajaydeepsingh",
28 | age:25
29 | }])
30 |
31 | console.log(b.toLocaleLowerCase());
32 | */
33 |
34 |
35 | // Assignment 2
36 | /*
37 | create a swap function that can takes two arguments of the same type
38 | arguments can be either two strings, number or booleans (both of the same type)
39 |
40 | the function should swap them and return an array with first element as the second one and vice versa */
41 |
42 | // function swap(a:T,b:U):[U,T]{
43 | // return [b,a]
44 | // }
45 |
46 | // const ans = swap(1,2);
47 |
48 |
49 | // Partials : A type could either exist or be set to undefined
50 |
51 | interface Todo {
52 | title: string,
53 | description: string,
54 | id: number,
55 | done: boolean;
56 | }
57 |
58 | type UpdateTodoInput = Partial;
59 |
60 | function updateTodo(id:number, newProp: UpdateTodoInput){
61 |
62 | }
63 |
64 | updateTodo(1,{
65 | description:"New identities"
66 | })
--------------------------------------------------------------------------------
/week2/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 |
3 |
--------------------------------------------------------------------------------
/week2/index.js:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ajaydeep123/100xdevsCohort/20b7c0ac5444177a23e8b3bf298adb3c3be87057/week2/index.js
--------------------------------------------------------------------------------
/week2/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "week2",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "start": "node index.js",
8 | "test": "echo \"Error: no test specified\" && exit 1"
9 | },
10 | "keywords": [],
11 | "author": "",
12 | "license": "ISC",
13 | "dependencies": {
14 | "express": "^4.18.2"
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/week2/rough.js:
--------------------------------------------------------------------------------
1 | let s= 'hello world '
2 | s = s.replace(/\s+/, ' ').trim();
3 | console.log(s.split(" "));
--------------------------------------------------------------------------------
/week3/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 |
--------------------------------------------------------------------------------
/week3/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "02-nodejs",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1",
8 | "test-fileServer": "npx jest ./tests/fileServer.test.js",
9 | "test-todoServer": "npx jest ./tests/todoServer.test.js",
10 | "test-authenticationServer": "npx jest ./tests/authenticationServer.test.js",
11 | "test-all": "npx jest ./tests/"
12 | },
13 | "keywords": [],
14 | "author": "",
15 | "license": "ISC",
16 | "devDependencies": {
17 | "jest": "^29.5.0",
18 | "supertest": "^6.3.3"
19 | },
20 | "jest": {
21 | "testTimeout": 10000
22 | },
23 | "dependencies": {
24 | "cors": "^2.8.5",
25 | "express": "^4.18.2",
26 | "uuid": "^9.0.0"
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/week3/todos.json:
--------------------------------------------------------------------------------
1 | []
--------------------------------------------------------------------------------
/week6/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
--------------------------------------------------------------------------------
/week6/index.js:
--------------------------------------------------------------------------------
1 | const app = require('express')();
2 | const http = require('http').Server(app);
3 | const io = require('socket.io')(http);
4 | const port = process.env.PORT || 3000;
5 |
6 | app.get('/', (req, res) => {
7 | res.sendFile(__dirname + '/index.html');
8 | });
9 |
10 | io.on('connection', (socket) => {
11 | socket.on('chat message', msg => {
12 | io.emit('chat message', msg);
13 | });
14 | });
15 |
16 | http.listen(port, () => {
17 | console.log(`Socket.IO server running at http://localhost:${port}/`);
18 | });
--------------------------------------------------------------------------------
/week6/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "week6",
3 | "version": "1.0.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "keywords": [],
10 | "author": "",
11 | "license": "ISC",
12 | "dependencies": {
13 | "express": "^4.18.2",
14 | "socket.io": "^4.7.1"
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/week8.2/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | node_modules
5 | .pnp
6 | .pnp.js
7 |
8 | # testing
9 | coverage
10 |
11 | # next.js
12 | .next/
13 | out/
14 | build
15 |
16 | # misc
17 | .DS_Store
18 | *.pem
19 |
20 | # debug
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 |
25 | # local env files
26 | .env
27 | .env.local
28 | .env.development.local
29 | .env.test.local
30 | .env.production.local
31 |
32 | # turbo
33 | .turbo
34 |
35 | # vercel
36 | .vercel
37 |
--------------------------------------------------------------------------------
/week8.2/.npmrc:
--------------------------------------------------------------------------------
1 | auto-install-peers = true
2 |
--------------------------------------------------------------------------------
/week8.2/apps/docs/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | extends: ["custom/next"],
3 | };
4 |
--------------------------------------------------------------------------------
/week8.2/apps/docs/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # next.js
12 | /.next/
13 | /out/
14 |
15 | # production
16 | /build
17 |
18 | # misc
19 | .DS_Store
20 | *.pem
21 |
22 | # debug
23 | npm-debug.log*
24 | yarn-debug.log*
25 | yarn-error.log*
26 |
27 | # local env files
28 | .env.local
29 | .env.development.local
30 | .env.test.local
31 | .env.production.local
32 |
33 | # vercel
34 | .vercel
35 |
--------------------------------------------------------------------------------
/week8.2/apps/docs/README.md:
--------------------------------------------------------------------------------
1 | ## Getting Started
2 |
3 | First, run the development server:
4 |
5 | ```bash
6 | yarn dev
7 | ```
8 |
9 | Open [http://localhost:3001](http://localhost:3001) with your browser to see the result.
10 |
11 | You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
12 |
13 | To create [API routes](https://nextjs.org/docs/app/building-your-application/routing/router-handlers) add an `api/` directory to the `app/` directory with a `route.ts` file. For individual endpoints, create a subfolder in the `api` directory, like `api/hello/route.ts` would map to [http://localhost:3001/api/hello](http://localhost:3001/api/hello).
14 |
15 | ## Learn More
16 |
17 | To learn more about Next.js, take a look at the following resources:
18 |
19 | - [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
20 | - [Learn Next.js](https://nextjs.org/learn/foundations/about-nextjs) - an interactive Next.js tutorial.
21 |
22 | You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
23 |
24 | ## Deploy on Vercel
25 |
26 | The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_source=github.com&utm_medium=referral&utm_campaign=turborepo-readme) from the creators of Next.js.
27 |
28 | Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
29 |
--------------------------------------------------------------------------------
/week8.2/apps/docs/app/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ajaydeep123/100xdevsCohort/20b7c0ac5444177a23e8b3bf298adb3c3be87057/week8.2/apps/docs/app/favicon.ico
--------------------------------------------------------------------------------
/week8.2/apps/docs/app/globals.css:
--------------------------------------------------------------------------------
1 | :root {
2 | --max-width: 1100px;
3 | --border-radius: 12px;
4 | --font-mono: ui-monospace, Menlo, Monaco, "Cascadia Mono", "Segoe UI Mono",
5 | "Roboto Mono", "Oxygen Mono", "Ubuntu Monospace", "Source Code Pro",
6 | "Fira Mono", "Droid Sans Mono", "Courier New", monospace;
7 |
8 | --foreground-rgb: 255, 255, 255;
9 | --background-start-rgb: 0, 0, 0;
10 | --background-end-rgb: 0, 0, 0;
11 |
12 | --callout-rgb: 20, 20, 20;
13 | --callout-border-rgb: 108, 108, 108;
14 | --card-rgb: 100, 100, 100;
15 | --card-border-rgb: 200, 200, 200;
16 |
17 | --glow-conic: conic-gradient(
18 | from 180deg at 50% 50%,
19 | #2a8af6 0deg,
20 | #a853ba 180deg,
21 | #e92a67 360deg
22 | );
23 | }
24 |
25 | * {
26 | box-sizing: border-box;
27 | padding: 0;
28 | margin: 0;
29 | }
30 |
31 | html,
32 | body {
33 | max-width: 100vw;
34 | overflow-x: hidden;
35 | }
36 |
37 | body {
38 | color: rgb(var(--foreground-rgb));
39 | background: linear-gradient(
40 | to bottom,
41 | transparent,
42 | rgb(var(--background-end-rgb))
43 | )
44 | rgb(var(--background-start-rgb));
45 | }
46 |
47 | a {
48 | color: inherit;
49 | text-decoration: none;
50 | }
51 |
--------------------------------------------------------------------------------
/week8.2/apps/docs/app/layout.tsx:
--------------------------------------------------------------------------------
1 | import "./globals.css";
2 | import type { Metadata } from "next";
3 | import { Inter } from "next/font/google";
4 |
5 | const inter = Inter({ subsets: ["latin"] });
6 |
7 | export const metadata: Metadata = {
8 | title: "Create Turborepo",
9 | description: "Generated by create turbo",
10 | };
11 |
12 | export default function RootLayout({
13 | children,
14 | }: {
15 | children: React.ReactNode;
16 | }): JSX.Element {
17 | return (
18 |
19 | {children}
20 |
21 | );
22 | }
23 |
--------------------------------------------------------------------------------
/week8.2/apps/docs/next-env.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 | ///
3 |
4 | // NOTE: This file should not be edited
5 | // see https://nextjs.org/docs/basic-features/typescript for more information.
6 |
--------------------------------------------------------------------------------
/week8.2/apps/docs/next.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | reactStrictMode: true,
3 | transpilePackages: ["ui"],
4 | };
5 |
--------------------------------------------------------------------------------
/week8.2/apps/docs/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "docs",
3 | "version": "1.0.0",
4 | "private": true,
5 | "scripts": {
6 | "dev": "next dev --port 3001",
7 | "build": "next build",
8 | "start": "next start",
9 | "lint": "next lint"
10 | },
11 | "dependencies": {
12 | "next": "^13.4.19",
13 | "react": "^18.2.0",
14 | "react-dom": "^18.2.0",
15 | "ui": "*"
16 | },
17 | "devDependencies": {
18 | "@next/eslint-plugin-next": "^13.4.19",
19 | "@types/node": "^17.0.12",
20 | "@types/react": "^18.0.22",
21 | "@types/react-dom": "^18.0.7",
22 | "eslint-config-custom": "*",
23 | "tsconfig": "*",
24 | "typescript": "^4.5.3"
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/week8.2/apps/docs/public/circles.svg:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/week8.2/apps/docs/public/next.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/week8.2/apps/docs/public/vercel.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/week8.2/apps/docs/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "tsconfig/nextjs.json",
3 | "compilerOptions": {
4 | "plugins": [{ "name": "next" }]
5 | },
6 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
7 | "exclude": ["node_modules"]
8 | }
9 |
--------------------------------------------------------------------------------
/week8.2/apps/web/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | extends: ["custom/next"],
3 | };
4 |
--------------------------------------------------------------------------------
/week8.2/apps/web/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # next.js
12 | /.next/
13 | /out/
14 |
15 | # production
16 | /build
17 |
18 | # misc
19 | .DS_Store
20 | *.pem
21 |
22 | # debug
23 | npm-debug.log*
24 | yarn-debug.log*
25 | yarn-error.log*
26 |
27 | # local env files
28 | .env.local
29 | .env.development.local
30 | .env.test.local
31 | .env.production.local
32 |
33 | # vercel
34 | .vercel
35 |
--------------------------------------------------------------------------------
/week8.2/apps/web/README.md:
--------------------------------------------------------------------------------
1 | ## Getting Started
2 |
3 | First, run the development server:
4 |
5 | ```bash
6 | yarn dev
7 | ```
8 |
9 | Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
10 |
11 | You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
12 |
13 | To create [API routes](https://nextjs.org/docs/app/building-your-application/routing/router-handlers) add an `api/` directory to the `app/` directory with a `route.ts` file. For individual endpoints, create a subfolder in the `api` directory, like `api/hello/route.ts` would map to [http://localhost:3000/api/hello](http://localhost:3000/api/hello).
14 |
15 | ## Learn More
16 |
17 | To learn more about Next.js, take a look at the following resources:
18 |
19 | - [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
20 | - [Learn Next.js](https://nextjs.org/learn/foundations/about-nextjs) - an interactive Next.js tutorial.
21 |
22 | You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
23 |
24 | ## Deploy on Vercel
25 |
26 | The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_source=github.com&utm_medium=referral&utm_campaign=turborepo-readme) from the creators of Next.js.
27 |
28 | Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
29 |
--------------------------------------------------------------------------------
/week8.2/apps/web/app/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Ajaydeep123/100xdevsCohort/20b7c0ac5444177a23e8b3bf298adb3c3be87057/week8.2/apps/web/app/favicon.ico
--------------------------------------------------------------------------------
/week8.2/apps/web/app/globals.css:
--------------------------------------------------------------------------------
1 | :root {
2 | --max-width: 1100px;
3 | --border-radius: 12px;
4 | --font-mono: ui-monospace, Menlo, Monaco, "Cascadia Mono", "Segoe UI Mono",
5 | "Roboto Mono", "Oxygen Mono", "Ubuntu Monospace", "Source Code Pro",
6 | "Fira Mono", "Droid Sans Mono", "Courier New", monospace;
7 |
8 | --foreground-rgb: 255, 255, 255;
9 | --background-start-rgb: 0, 0, 0;
10 | --background-end-rgb: 0, 0, 0;
11 |
12 | --callout-rgb: 20, 20, 20;
13 | --callout-border-rgb: 108, 108, 108;
14 | --card-rgb: 100, 100, 100;
15 | --card-border-rgb: 200, 200, 200;
16 |
17 | --glow-conic: conic-gradient(
18 | from 180deg at 50% 50%,
19 | #2a8af6 0deg,
20 | #a853ba 180deg,
21 | #e92a67 360deg
22 | );
23 | }
24 |
25 | * {
26 | box-sizing: border-box;
27 | padding: 0;
28 | margin: 0;
29 | }
30 |
31 | html,
32 | body {
33 | max-width: 100vw;
34 | overflow-x: hidden;
35 | }
36 |
37 | body {
38 | color: rgb(var(--foreground-rgb));
39 | background: linear-gradient(
40 | to bottom,
41 | transparent,
42 | rgb(var(--background-end-rgb))
43 | )
44 | rgb(var(--background-start-rgb));
45 | }
46 |
47 | a {
48 | color: inherit;
49 | text-decoration: none;
50 | }
51 |
--------------------------------------------------------------------------------
/week8.2/apps/web/app/layout.tsx:
--------------------------------------------------------------------------------
1 | import "./globals.css";
2 | import type { Metadata } from "next";
3 | import { Inter } from "next/font/google";
4 |
5 | const inter = Inter({ subsets: ["latin"] });
6 |
7 | export const metadata: Metadata = {
8 | title: "Create Turborepo",
9 | description: "Generated by create turbo",
10 | };
11 |
12 | export default function RootLayout({
13 | children,
14 | }: {
15 | children: React.ReactNode;
16 | }): JSX.Element {
17 | return (
18 |
19 | {children}
20 |
21 | );
22 | }
23 |
--------------------------------------------------------------------------------
/week8.2/apps/web/app/page.tsx:
--------------------------------------------------------------------------------
1 | import styles from "./page.module.css";
2 | import { Signup } from "ui";
3 | export default function Page(): JSX.Element {
4 | return (
5 |
6 |
7 |
8 | );
9 | }
10 |
--------------------------------------------------------------------------------
/week8.2/apps/web/next-env.d.ts:
--------------------------------------------------------------------------------
1 | ///
2 | ///
3 |
4 | // NOTE: This file should not be edited
5 | // see https://nextjs.org/docs/basic-features/typescript for more information.
6 |
--------------------------------------------------------------------------------
/week8.2/apps/web/next.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | reactStrictMode: true,
3 | transpilePackages: ["ui"],
4 | };
5 |
--------------------------------------------------------------------------------
/week8.2/apps/web/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "web",
3 | "version": "1.0.0",
4 | "private": true,
5 | "scripts": {
6 | "dev": "next dev",
7 | "build": "next build",
8 | "start": "next start",
9 | "lint": "next lint"
10 | },
11 | "dependencies": {
12 | "next": "^13.4.19",
13 | "react": "^18.2.0",
14 | "react-dom": "^18.2.0",
15 | "ui": "*"
16 | },
17 | "devDependencies": {
18 | "@next/eslint-plugin-next": "^13.4.19",
19 | "@types/node": "^17.0.12",
20 | "@types/react": "^18.0.22",
21 | "@types/react-dom": "^18.0.7",
22 | "eslint-config-custom": "*",
23 | "tsconfig": "*",
24 | "typescript": "^4.5.3"
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/week8.2/apps/web/public/circles.svg:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/week8.2/apps/web/public/next.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/week8.2/apps/web/public/vercel.svg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/week8.2/apps/web/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "tsconfig/nextjs.json",
3 | "compilerOptions": {
4 | "plugins": [{ "name": "next" }]
5 | },
6 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
7 | "exclude": ["node_modules"]
8 | }
9 |
--------------------------------------------------------------------------------
/week8.2/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "private": true,
3 | "scripts": {
4 | "build": "turbo run build",
5 | "dev": "turbo run dev",
6 | "lint": "turbo run lint",
7 | "format": "prettier --write \"**/*.{ts,tsx,md}\""
8 | },
9 | "devDependencies": {
10 | "eslint": "^8.48.0",
11 | "prettier": "^3.0.3",
12 | "tsconfig": "*",
13 | "turbo": "latest"
14 | },
15 | "name": "week8.2",
16 | "packageManager": "npm@9.6.6",
17 | "workspaces": [
18 | "apps/*",
19 | "packages/*"
20 | ]
21 | }
22 |
--------------------------------------------------------------------------------
/week8.2/packages/eslint-config-custom/README.md:
--------------------------------------------------------------------------------
1 | # `@turbo/eslint-config`
2 |
3 | Collection of internal eslint configurations.
4 |
--------------------------------------------------------------------------------
/week8.2/packages/eslint-config-custom/library.js:
--------------------------------------------------------------------------------
1 | const { resolve } = require("node:path");
2 |
3 | const project = resolve(process.cwd(), "tsconfig.json");
4 |
5 | /*
6 | * This is a custom ESLint configuration for use with
7 | * typescript packages.
8 | *
9 | * This config extends the Vercel Engineering Style Guide.
10 | * For more information, see https://github.com/vercel/style-guide
11 | *
12 | */
13 |
14 | module.exports = {
15 | extends: [
16 | "@vercel/style-guide/eslint/node",
17 | "@vercel/style-guide/eslint/typescript",
18 | ].map(require.resolve),
19 | parserOptions: {
20 | project,
21 | },
22 | globals: {
23 | React: true,
24 | JSX: true,
25 | },
26 | settings: {
27 | "import/resolver": {
28 | typescript: {
29 | project,
30 | },
31 | },
32 | },
33 | ignorePatterns: ["node_modules/", "dist/"],
34 | };
35 |
--------------------------------------------------------------------------------
/week8.2/packages/eslint-config-custom/next.js:
--------------------------------------------------------------------------------
1 | const { resolve } = require("node:path");
2 |
3 | const project = resolve(process.cwd(), "tsconfig.json");
4 |
5 | /*
6 | * This is a custom ESLint configuration for use with
7 | * Next.js apps.
8 | *
9 | * This config extends the Vercel Engineering Style Guide.
10 | * For more information, see https://github.com/vercel/style-guide
11 | *
12 | */
13 |
14 | module.exports = {
15 | extends: [
16 | "@vercel/style-guide/eslint/node",
17 | "@vercel/style-guide/eslint/browser",
18 | "@vercel/style-guide/eslint/typescript",
19 | "@vercel/style-guide/eslint/react",
20 | "@vercel/style-guide/eslint/next",
21 | "eslint-config-turbo",
22 | ].map(require.resolve),
23 | parserOptions: {
24 | project,
25 | },
26 | globals: {
27 | React: true,
28 | JSX: true,
29 | },
30 | settings: {
31 | "import/resolver": {
32 | typescript: {
33 | project,
34 | },
35 | },
36 | },
37 | ignorePatterns: ["node_modules/", "dist/"],
38 | // add rules configurations here
39 | rules: {
40 | "import/no-default-export": "off",
41 | },
42 | };
43 |
--------------------------------------------------------------------------------
/week8.2/packages/eslint-config-custom/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "eslint-config-custom",
3 | "license": "MIT",
4 | "version": "0.0.0",
5 | "private": true,
6 | "devDependencies": {
7 | "@vercel/style-guide": "^5.0.0",
8 | "eslint-config-turbo": "^1.10.12",
9 | "typescript": "^4.5.3"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/week8.2/packages/eslint-config-custom/react-internal.js:
--------------------------------------------------------------------------------
1 | const { resolve } = require("node:path");
2 |
3 | const project = resolve(process.cwd(), "tsconfig.json");
4 |
5 | /*
6 | * This is a custom ESLint configuration for use with
7 | * internal (bundled by their consumer) libraries
8 | * that utilize React.
9 | *
10 | * This config extends the Vercel Engineering Style Guide.
11 | * For more information, see https://github.com/vercel/style-guide
12 | *
13 | */
14 |
15 | module.exports = {
16 | extends: [
17 | "@vercel/style-guide/eslint/browser",
18 | "@vercel/style-guide/eslint/typescript",
19 | "@vercel/style-guide/eslint/react",
20 | ].map(require.resolve),
21 | parserOptions: {
22 | project,
23 | },
24 | globals: {
25 | JSX: true,
26 | },
27 | settings: {
28 | "import/resolver": {
29 | typescript: {
30 | project,
31 | },
32 | },
33 | },
34 | ignorePatterns: ["node_modules/", "dist/", ".eslintrc.js"],
35 |
36 | rules: {
37 | // add specific rules configurations here
38 | },
39 | };
40 |
--------------------------------------------------------------------------------
/week8.2/packages/tsconfig/base.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://json.schemastore.org/tsconfig",
3 | "display": "Default",
4 | "compilerOptions": {
5 | "composite": false,
6 | "declaration": true,
7 | "declarationMap": true,
8 | "esModuleInterop": true,
9 | "forceConsistentCasingInFileNames": true,
10 | "inlineSources": false,
11 | "isolatedModules": true,
12 | "moduleResolution": "node",
13 | "noUnusedLocals": false,
14 | "noUnusedParameters": false,
15 | "preserveWatchOutput": true,
16 | "skipLibCheck": true,
17 | "strict": true,
18 | "strictNullChecks": true
19 | },
20 | "exclude": ["node_modules"]
21 | }
22 |
--------------------------------------------------------------------------------
/week8.2/packages/tsconfig/nextjs.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://json.schemastore.org/tsconfig",
3 | "display": "Next.js",
4 | "extends": "./base.json",
5 | "compilerOptions": {
6 | "plugins": [{ "name": "next" }],
7 | "allowJs": true,
8 | "declaration": false,
9 | "declarationMap": false,
10 | "incremental": true,
11 | "jsx": "preserve",
12 | "lib": ["dom", "dom.iterable", "esnext"],
13 | "module": "esnext",
14 | "noEmit": true,
15 | "resolveJsonModule": true,
16 | "strict": false,
17 | "target": "es5"
18 | },
19 | "include": ["src", "next-env.d.ts"],
20 | "exclude": ["node_modules"]
21 | }
22 |
--------------------------------------------------------------------------------
/week8.2/packages/tsconfig/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "tsconfig",
3 | "version": "0.0.0",
4 | "private": true,
5 | "license": "MIT",
6 | "publishConfig": {
7 | "access": "public"
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/week8.2/packages/tsconfig/react-library.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://json.schemastore.org/tsconfig",
3 | "display": "React Library",
4 | "extends": "./base.json",
5 | "compilerOptions": {
6 | "jsx": "react-jsx",
7 | "lib": ["ES2015", "DOM"],
8 | "module": "ESNext",
9 | "target": "es6"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/week8.2/packages/ui/.eslintrc.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | extends: ["custom/react-internal"],
3 | };
4 |
--------------------------------------------------------------------------------
/week8.2/packages/ui/Signup.tsx:
--------------------------------------------------------------------------------
1 | export const Signup = () => {
2 | return (
3 | <>
4 |
11 | >
12 | )
13 | }
14 |
--------------------------------------------------------------------------------
/week8.2/packages/ui/card.tsx:
--------------------------------------------------------------------------------
1 | import * as React from "react";
2 |
3 | export function Card({
4 | className,
5 | title,
6 | children,
7 | href,
8 | }: {
9 | className?: string;
10 | title: string;
11 | children: React.ReactNode;
12 | href: string;
13 | }): JSX.Element {
14 | return (
15 |
21 |
22 | {title} ->
23 |
24 | {children}
25 |
26 | );
27 | }
28 |
--------------------------------------------------------------------------------
/week8.2/packages/ui/index.tsx:
--------------------------------------------------------------------------------
1 | // component exports
2 | export { Card } from "./card";
3 | export * from "./Signup";
--------------------------------------------------------------------------------
/week8.2/packages/ui/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "ui",
3 | "version": "0.0.0",
4 | "main": "./index.tsx",
5 | "types": "./index.tsx",
6 | "license": "MIT",
7 | "scripts": {
8 | "lint": "eslint .",
9 | "generate:component": "turbo gen react-component"
10 | },
11 | "devDependencies": {
12 | "@turbo/gen": "^1.10.12",
13 | "@types/node": "^20.5.2",
14 | "@types/react": "^18.2.0",
15 | "@types/react-dom": "^18.2.0",
16 | "eslint-config-custom": "*",
17 | "react": "^18.2.0",
18 | "tsconfig": "*",
19 | "typescript": "^4.5.2"
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/week8.2/packages/ui/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "tsconfig/react-library.json",
3 | "include": ["."],
4 | "exclude": ["dist", "build", "node_modules"]
5 | }
6 |
--------------------------------------------------------------------------------
/week8.2/packages/ui/turbo/generators/config.ts:
--------------------------------------------------------------------------------
1 | import type { PlopTypes } from "@turbo/gen";
2 |
3 | // Learn more about Turborepo Generators at https://turbo.build/repo/docs/core-concepts/monorepos/code-generation
4 |
5 | // eslint-disable-next-line import/no-default-export -- Turbo generators require default export
6 | export default function generator(plop: PlopTypes.NodePlopAPI): void {
7 | // A simple generator to add a new React component to the internal UI library
8 | plop.setGenerator("react-component", {
9 | description: "Adds a new react component",
10 | prompts: [
11 | {
12 | type: "input",
13 | name: "name",
14 | message: "What is the name of the component?",
15 | },
16 | ],
17 | actions: [
18 | {
19 | type: "add",
20 | path: "{{pascalCase name}}.tsx",
21 | templateFile: "templates/component.hbs",
22 | },
23 | {
24 | type: "append",
25 | path: "index.tsx",
26 | pattern: /(?\/\/ component exports)/g,
27 | template: 'export * from "./{{pascalCase name}}";',
28 | },
29 | ],
30 | });
31 | }
32 |
--------------------------------------------------------------------------------
/week8.2/packages/ui/turbo/generators/templates/component.hbs:
--------------------------------------------------------------------------------
1 | import * as React from "react";
2 |
3 | interface Props {
4 | children?: React.ReactNode;
5 | }
6 |
7 | export const {{ pascalCase name }} = ({ children }: Props) => {
8 | return (
9 |
10 |
{{ name }}
11 | {children}
12 |
13 | );
14 | };
15 |
--------------------------------------------------------------------------------
/week8.2/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": "tsconfig/base.json"
3 | }
4 |
--------------------------------------------------------------------------------
/week8.2/turbo.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://turbo.build/schema.json",
3 | "globalDependencies": ["**/.env.*local"],
4 | "pipeline": {
5 | "build": {
6 | "dependsOn": ["^build"],
7 | "outputs": [".next/**", "!.next/cache/**"]
8 | },
9 | "lint": {},
10 | "dev": {
11 | "cache": false,
12 | "persistent": true
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------