가. 아 파일분리 정신혼미해
백엔드 파일 순서(users 관련)
1. server.js
2. app.js
3. index.js
4. users.routes.js
5. output.routes.js : 콘트롤러 output 모음 + render(authMiddleware)
6. users_output.controller.js : render 코드 모음
7. users.controller.js
8. users.service.js
9. users.repository.js
나. 아 파라미터 정신혼미해
1. userInfo 찾아 삼만리
Users 테이블의 id 필드를 참조하는 외래키 userId였음
* 5_token_FK5.js
await queryInterface.addConstraint('Tokens', {
// FK를 설정할 테이블 (DB에 있는 테이블 이름과 같아야한다.)
fields: ['userId'], // FK로 등록할 필드 이름
type: 'foreign key',
name: 'users_tokens_id_fk',
references: {
table: 'Users', // 참조할 테이블 (DB에 있는 테이블 이름과 같아야한다.)
field: 'id', // 참조할 필드 이름
},
onDelete: 'cascade',
onUpdate: 'cascade',
});
},
다-1. [문제사항] 초기세팅
1. package.json에 nodemon 부재하나 script에는 관련 코드가 있음
"start": "nodemon ./bin/server.js",
다-2. [문제사항] 코드
1. 주문 신청 페이지
- 날짜 중 연도를 111111로 입력해 오류 발생
- app이 crash되며 서버가 끊김 "[nodemon] app crashed - waiting for file changes before starting..."
Executing (default): INSERT INTO `Orders` (`id`,`ownerId`,`kinds`,`details`,`pickup`,`imageUrl`,`createdAt`,`updatedAt`) VALUES (DEFAULT,?,?,?,?,?,?,?);
Error
at Query.run (C:\Users\user\Desktop\bootcamp_nodejs\99_teamstudy\save_my_keyboard\app\node_modules\sequelize\lib\dialects\mysql\query.js:52:25)
at C:\Users\user\Desktop\bootcamp_nodejs\99_teamstudy\save_my_keyboard\app\node_modules\sequelize\lib\sequelize.js:314:28
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async MySQLQueryInterface.insert (C:\Users\user\Desktop\bootcamp_nodejs\99_teamstudy\save_my_keyboard\app\node_modules\sequelize\lib\dialects\abstract\query-interface.js:308:21)
at async Order.save (C:\Users\user\Desktop\bootcamp_nodejs\99_teamstudy\save_my_keyboard\app\node_modules\sequelize\lib\model.js:2432:35)
at async Order.create (C:\Users\user\Desktop\bootcamp_nodejs\99_teamstudy\save_my_keyboard\app\node_modules\sequelize\lib\model.js:1344:12)
at async OrdersRepository.createOrder (C:\Users\user\Desktop\bootcamp_nodejs\99_teamstudy\save_my_keyboard\app\src\repositories\orders.repository.js:34:22)
at async OrdersService.createOrder (C:\Users\user\Desktop\bootcamp_nodejs\99_teamstudy\save_my_keyboard\app\src\services\orders.service.js:70:26)
at async createOrder (C:\Users\user\Desktop\bootcamp_nodejs\99_teamstudy\save_my_keyboard\app\src\controllers\orders.controller.js:24:22) {
name: 'SequelizeDatabaseError',
parent: Error: Incorrect datetime value: '111111-11-11 02:11:00' for column 'pickup' at row
1
at Packet.asError (C:\Users\user\Desktop\bootcamp_nodejs\99_teamstudy\save_my_keyboard\app\node_modules\mysql2\lib\packets\packet.js:728:17)
at Execute.execute (C:\Users\user\Desktop\bootcamp_nodejs\99_teamstudy\save_my_keyboard\app\node_modules\mysql2\lib\commands\command.js:29:26)
at Connection.handlePacket (C:\Users\user\Desktop\bootcamp_nodejs\99_teamstudy\save_my_keyboard\app\node_modules\mysql2\lib\connection.js:456:32)
at PacketParser.onPacket (C:\Users\user\Desktop\bootcamp_nodejs\99_teamstudy\save_my_keyboard\app\node_modules\mysql2\lib\connection.js:85:12)
at PacketParser.executeStart (C:\Users\user\Desktop\bootcamp_nodejs\99_teamstudy\save_my_keyboard\app\node_modules\mysql2\lib\packet_parser.js:75:16)
at Socket.<anonymous> (C:\Users\user\Desktop\bootcamp_nodejs\99_teamstudy\save_my_keyboard\app\node_modules\mysql2\lib\connection.js:92:25)
at Socket.emit (node:events:513:28)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)
at Readable.push (node:internal/streams/readable:234:10) {
code: 'ER_TRUNCATED_WRONG_VALUE',
errno: 1292,
sqlState: '22007',
sqlMessage: "Incorrect datetime value: '111111-11-11 02:11:00' for column 'pickup' at row
1",
sql: 'INSERT INTO `Orders` (`id`,`ownerId`,`kinds`,`details`,`pickup`,`imageUrl`,`createdAt`,`updatedAt`) VALUES (DEFAULT,?,?,?,?,?,?,?);',
parameters: [
1,
'테스트 키보드 종류',
'테스트 요청사항',
'111111-11-11 02:11:00',
'20230114132928_testimg.jpg',
'2023-01-14 04:29:28',
'2023-01-14 04:29:28'
]
},
original: Error: Incorrect datetime value: '111111-11-11 02:11:00' for column 'pickup' at row 1
at Packet.asError (C:\Users\user\Desktop\bootcamp_nodejs\99_teamstudy\save_my_keyboard\app\node_modules\mysql2\lib\packets\packet.js:728:17)
at Execute.execute (C:\Users\user\Desktop\bootcamp_nodejs\99_teamstudy\save_my_keyboard\app\node_modules\mysql2\lib\commands\command.js:29:26)
at Connection.handlePacket (C:\Users\user\Desktop\bootcamp_nodejs\99_teamstudy\save_my_keyboard\app\node_modules\mysql2\lib\connection.js:456:32)
at PacketParser.onPacket (C:\Users\user\Desktop\bootcamp_nodejs\99_teamstudy\save_my_keyboard\app\node_modules\mysql2\lib\connection.js:85:12)
at PacketParser.executeStart (C:\Users\user\Desktop\bootcamp_nodejs\99_teamstudy\save_my_keyboard\app\node_modules\mysql2\lib\packet_parser.js:75:16)
at Socket.<anonymous> (C:\Users\user\Desktop\bootcamp_nodejs\99_teamstudy\save_my_keyboard\app\node_modules\mysql2\lib\connection.js:92:25)
at Socket.emit (node:events:513:28)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)
at Readable.push (node:internal/streams/readable:234:10) {
code: 'ER_TRUNCATED_WRONG_VALUE',
errno: 1292,
sqlState: '22007',
sqlMessage: "Incorrect datetime value: '111111-11-11 02:11:00' for column 'pickup' at row
1",
sql: 'INSERT INTO `Orders` (`id`,`ownerId`,`kinds`,`details`,`pickup`,`imageUrl`,`createdAt`,`updatedAt`) VALUES (DEFAULT,?,?,?,?,?,?,?);',
parameters: [
1,
'테스트 키보드 종류',
'테스트 요청사항',
'111111-11-11 02:11:00',
'20230114132928_testimg.jpg',
'2023-01-14 04:29:28',
'2023-01-14 04:29:28'
]
},
sql: 'INSERT INTO `Orders` (`id`,`ownerId`,`kinds`,`details`,`pickup`,`imageUrl`,`createdAt`,`updatedAt`) VALUES (DEFAULT,?,?,?,?,?,?,?);',
parameters: [
1,
'테스트 키보드 종류',
'테스트 요청사항',
'111111-11-11 02:11:00',
'20230114132928_testimg.jpg',
'2023-01-14 04:29:28',
'2023-01-14 04:29:28'
]
}
C:\Users\user\Desktop\bootcamp_nodejs\99_teamstudy\save_my_keyboard\app\src\controllers\orders.controller.js:25
res.status(response.code).json({ message: response.message });
^
TypeError: Cannot read properties of undefined (reading 'code')
at createOrder (C:\Users\user\Desktop\bootcamp_nodejs\99_teamstudy\save_my_keyboard\app\src\controllers\orders.controller.js:25:25)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Node.js v18.12.1
[nodemon] app crashed - waiting for file changes before starting...
2. (사장) 주문 접수 내역
- 주문 상태 변경 작동 안함 ('수거중' 버튼 클릭 시)
- 수거중 버튼 상단의 버튼 클릭 시 오류 발생
admin:69 Uncaught ReferenceError: statuschange is not defined
at HTMLButtonElement.onclick (admin:69:113)
3. (손님) 주문 취소하기
- 주문 취소 작동 안함
- PATCH http://localhost:3000/api/orders/1 500 (Internal Server Error)
다. ??? !!! +++
1. app 최상위 폴더를 만든 이유가 있느지?
2.app > bin > server.js
1)
- 주문 취소 작동 안함