본문 바로가기

전체 글

(68)
How do I do object CRUD? How do CRUD with models with express.js? I wanted to know the process My project's structure MyProject - server.js - model - User.js - routes - users.js - controllers - users.js server.js This get all of the http request and connect with others. now this will send data to routes/user.js // Bring express framework const express = require('express'); // Route file const users = require('./routes/u..
UdemyAPI_Define model schema User Schema const mongoose = require('mongoose'); const UserSchema = new mongoose.Schema({ name: { type: String, required: [true, 'Please add a name'] }, email: { type: String, required: [true,'Please add an email'], unique: true, match: [ /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/, 'Please add a valid email' ] }, role: { type: String, enum: ['user', 'instructor'], defalut: 'user' }, passwo..
"Udemy" API by myself What do I have to do first? 1. Define model schemas 2. Inspector/User CRUD + ErrorHandler middleware 3. Course CRUD 4. Review CRUD (all objects CURD is public till this step) 5. put Authentication and Permission - User/Instructor Register / Encrypting password / Authentication: JWT / Auth Protect / Role Authorization - User CRUD - Course CRUD - Review CURD 6. Detail Query - Filtering/ Sorting/ S..
Udemy course spec/APIs Courses List all courses in the database - Pagination - Select specific fields(category) in result - Limit number of results - Filter by fields Search Course by user input Get single course Create new course - Authenticated users only - Must have the role "instructor" - Field validation via Mongoose - Photo will be uploaded to local filesystem(required:false) Update course - Instructor only - Va..
How to manage of 1:N relationship? mongoose https://mongoosejs.com/docs/tutorials/virtuals.html recommand look this site slowly. I wondered how models are related each other and how they work? MongoDB is noSQL(: Not only SQL) so I needed to change the relationship of models. Because I just know RDBMS. RDBMS is sophisticate to defining models. but mongoDB is not that much. 1. In 1:N relationship, only 'N' object has foreignkey. '1' object ..
The process error handling 1. Occured some Error. ex. inputed ungettable type of object or bad request 2. If we let the error be/ if we dont do anything with this error, the server is shut donwed. so we need to controll or handle errors. 3. Catch errers ! use "try { } catch { }" or anything we can. I made some middleware to catch err and connect with handler const asyncHandler = fn => (req, res, next) => Promise.resolve(f..
탑 _프로그래머스 var result = []; var count = 0; for (var i = height.length-1; i>=0; i--) { var unshifted = false; for (var j = i-1; j>=0; j--) { if (height[i] < height[j]) { result.unshift( (j+1) ); unshifted = true; break; } } if (unshifted == false){ result.unshift(0); } } 다른이들의 답이 궁금하지만, 다른 공부하다 못참겠어서 잠깐하고 넘어가는거라 내일 정리 !
k번째수 function solution(array, commands) { var answer = []; for(let i = 0; i a-b); const tmpAnswer = splitArray[commands[i][2]-1] answer.push(tmpAnswer); } return answer; } slice 두번째 인자로 "commands[i][1] -1"을 줘버려가지고 헤맸다. 역시 문법에 익숙해져야합니다 . sort 정렬이 무조건 낮은 순서대로 되는게 아니다. [1, 2, 10, 3] 이렇게 있는 것을 .sort..