cumulonimbus69
@aragornkim9515
Reviews Written
4
Average Rating
4.8
๋ฆ์์ง๋ง ์ฝ๋ฉ ๊ณต๋ถ ์ค
Posts
Q&A
ํธ๋์ญ์ ๊ธฐ๋ฅ์ ์๋น์ค ํจ์๋ก ๊ตฌํํ๋ ๋ฐฉ๋ฒ
๊ฐ๋ฅด์ณ ์ฃผ์ ๊ตฌ๋ฌธ์ผ๋ก ๋ณ๊ฒฝ์ ํ๋ ๋์์ด ์ ๋ฉ๋๋ค ๊ฐ์ฌํฉ๋๋ค์ฐ๊ฒฐํด์ฃผ์ ์ ํฌ๋ธ ๋ด์ฉ๋ ์ ๋ณด์๋๋ฐ ๊ทธ๋๋ targets.forEach((good) => auctionedOff(good)());์ด ๋ถ๋ถ์์ ๋ง์ง๋ง์ ๋น ๊ดํธ๋ฅผ ๋ถ์ด๋ ์๋ฏธ๋ฅผ ํด์ํ๊ธฐ ์ด๋ ค์ ๋ง์ง๋ง์ผ๋ก ํ ๋ฒ ๋ ์ง๋ฌธ ๋๋ฆฝ๋๋ค์ฐ๊ฒฐ ํด์ฃผ์ ์ ํฌ๋ธ ๋ด์ฉ์ ๋ฐํ์ผ๋ก "auctionedOff(good) ๋ค์ ์๋ ๋น๊ดํธ๋ auctionedOff(good)์ ๋ฆฌํด๊ฐ์ธ { }๋ก ๊ฐ์ธ์ง ๋ถ๋ถ์ ๋ถ๋ฌ์ค๊ธฐ ์ํจ์ด๊ณ ์ด ๋ถ๋ถ์ ๋ณ๊ฒฝ ์ ForEachํจ์ ๊ดํธ ๋ด์ ํ์ดํ ์ดํ {} ๋ธ๋ญ๊ณผ ๋์ผํ๋ฏ๋ก ๋์ฒดํ ์ ์๋ค" ๋ก ํด์ ํ๋ฉด ๋ ์ง ์ง๋ฌธ ๋๋ฆฝ๋๋ค
- 0
- 6
- 346
Q&A
ํธ๋์ญ์ ๊ธฐ๋ฅ์ ์๋น์ค ํจ์๋ก ๊ตฌํํ๋ ๋ฐฉ๋ฒ
๋ง์ํ์ ๋ฐ๋ก auctionedOff ํจ์๋ฅผ ๋ค์๊ณผ ๊ฐ์ด ๋ฐ๊พธ์ด ์คํํ๋ ์ ๋์๊ฐ๋๋ค.์์ ํ ํจ์ :const sequelize = require('sequelize'); const { Auction , Good, User}= require('../models'); exports.auctionedOff = ( good ) => async () => { const t = await sequelize.transaction(); try { const success = await Auction.findOne({ where: { GoodId: good.id }, order: [['bid', 'DESC']], transaction : t, }); if (!success) { return; } await good.setSold(success.UserId); //๋์ฐฐ await User.update({ money: sequelize.literal(`money - ${success.bid}`), }, { where: { id: success.UserId }, transaction: t, }); await t.commit(); } catch (error) { await t.rollback(); } };๊ทธ๋ฐ๋ฐ ์์ ํํ๋ฅผ checkAuction.js ๋ถ๋ถ์ 24์๊ฐ์ด ์ง๋ ์์ดํ ์ ๋ํด ๋์ฐฐ์๋ฅผ ์ง์ ํ๋ ForEach ํจ์ ๋ถ๋ถ์๋ ์ ์ฉํด ๋ณด๋ ค๊ณ ํ๋๋ฐ ์ฌ๊ธฐ๋ ์๋๋๋ฐ ์ด์ ๊ฐ ๋ญ๊น์?์๋ํ ์ฝ๋ : module.exports = async () => { console.log('checkAuction'); try { const yesterday = new Date(); yesterday.setDate(yesterday.getDate() - 1); // ์ด์ ์๊ฐ const targets = await Good.findAll({ // 24์๊ฐ์ด ์ง๋ ๋์ฐฐ์ ์๋ ๊ฒฝ๋งค๋ค where: { SoldId: null, createdAt: { [Op.lte]: yesterday }, }, }); targets.forEach(auctionedOff(good));์๋์ ๊ฐ์ด auctionedOff ๋ก ๋ฐ๊พธ๊ธฐ ์ ์ ํ์ธ์ฐจ ์์ ํ์ ๋๋ ์ ์์ ์ผ๋ก ๋์ฐฐ๋ ๋ฌผ๊ฑด์ ๋ํด ๋์ฐฐ์๋ฅผ ์ง์ ํ๊ณ ๋์ฐฐ์์ ๊ธ์ก๋ ๋นผ๋ ํ๋ก์ธ์ค๊ฐ ์๋์์ต๋๋คmodule.exports = async () => { console.log('checkAuction'); try { const yesterday = new Date(); yesterday.setDate(yesterday.getDate() - 1); // ์ด์ ์๊ฐ const targets = await Good.findAll({ // 24์๊ฐ์ด ์ง๋ ๋์ฐฐ์ ์๋ ๊ฒฝ๋งค๋ค where: { SoldId: null, createdAt: { [Op.lte]: yesterday }, }, }); targets.forEach( async (good) => { const t = await sequelize.transaction(); try { const success = await Auction.findOne({ where: { GoodId: good.id }, order: [['bid', 'DESC']], transaction : t, }); if (!success) { return; } console.log('***checkauction',success.UserId); await good.setSold(success.UserId); await User.update({ money: sequelize.literal(`money - ${success.bid}`), }, { where: { id: success.UserId }, transacion: t, }); await t.commit(); } catch (error) { await t.rollback(); } });
- 0
- 6
- 346
Q&A
ํธ๋์ญ์ ๊ธฐ๋ฅ์ ์๋น์ค ํจ์๋ก ๊ตฌํํ๋ ๋ฐฉ๋ฒ
๊ฐ์ฌํฉ๋๋ค ์์ ๋ฐ์ํ ๋ฉ์์ง๋ ํด๊ฒฐ ๋์๋๋ฐ ๊ฐ๋ฅด์ณ์ฃผ์ ๋ฐ๋ก ์์ ํ ์ดํ์ ๋ค์๊ณผ ๊ฐ์ ์ค๋ฅ ๋ฉ์์ง๊ฐ ๋ ๋น๋๋ค(์ฌ์ง)์ฐธ๊ณ ํ์๋ผ ๋ก๊ทธ ์๋ฌ ๋ฉ์์ง๋ ์ฒจ๋ถ ํฉ๋๋ค๋์ ๋ ๋ ๊ฒ์ "RangeError" ๋ผ๊ณ ๋น๋๋ค๋ง์์๋ "TypeError" ์๋๋ฐ ๋ฐํด์.. GET /main.css 304 0.333 ms - - Executing (default): SELECT `id`, `email`, `nick`, `password`, `money`, `createdAt`, `updatedAt`, `deletedAt` FROM `users` AS `User` WHERE (`User`.`deletedAt` IS NULL AND `User`.`id` = 1); Executing (default): INSERT INTO `goods` (`id`,`name`,`img`,`price`,`createdAt`,`updatedAt`,`OwnerId`) VALUES (DEFAULT,?,?,?,?,?,?); RangeError: The job method must be a function. at Object.scheduleJob (/Users/skychome/Desktop/My_Work/node_work/node_practice/node_auction/node_modules/node-schedule/lib/schedule.js:34:11) at exports.createGood (/Users/skychome/Desktop/My_Work/node_work/node_practice/node_auction/controllers/index.js:48:26) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) Executing (dd5254a0-4b7a-4cbd-bdd2-5b2f494da1e1): START TRANSACTION; POST /good 500 116.267 ms - 1684 Executing (dd5254a0-4b7a-4cbd-bdd2-5b2f494da1e1): SELECT `id`, `bid`, `msg`, `createdAt`, `updatedAt`, `deletedAt`, `UserId`, `GoodId` FROM `auctions` AS `Auction` WHERE (`Auction`.`deletedAt` IS NULL AND `Auction`.`GoodId` = 13) ORDER BY `Auction`.`bid` DESC LIMIT 1; GET /main.css 304 0.313 ms - -
- 0
- 6
- 346
Q&A
๊ฒฝ๋งค ์งํ ๋ฉ์ธ ํ๋ฉด์์ ์ค๋ฅ ๋ฐ์
๊ฐ์ฌ๋, ๊ฒฐ๊ตญ์ good.js ํ์ผ์ associate ํจ์๊ฐ associte ๋ก ์ค์๊ฐ ์์๋ค์ ์์ ํ๋ ์ ๋ฉ๋๋ค^^
- 0
- 3
- 274
Q&A
๊ฒฝ๋งค ์งํ ๋ฉ์ธ ํ๋ฉด์์ ์ค๋ฅ ๋ฐ์
๊ฐ์ฌ๋,๋ง์ ํ์ ๋ฐ๋ก workbench์ ์ด์ํ๊ฒ goods table์ SoldID ์นผ๋ผ์ด ์์ฑ ๋์ด ์์ง ์์ต๋๋ค. auctions table์๋ GoodId, UserId ์นผ๋ผ์ด ์์ฑ๋์ด ์๋๋ฐ์..(์ฌ์ง)์ฐธ๊ณ ๋ก models/index.js ํ์ผ ์ฝ๋๋ฅผ ์ฌ๋ฆฝ๋๋คconst Sequelize = require('sequelize'); const fs = require('fs'); const path = require('path'); const env = process.env.NODE_ENV || 'development'; const config = require('../config/config')[env]; const db = {}; const sequelize = new Sequelize( config.database, config.username, config.password, config, ); db.sequelize = sequelize; //db.Sequelize = Sequelize; const basename = path.basename(__filename); //ํ์ฌ ์์ ํ๋ file ์ด๋ฆ ์ฐพ์๋ ค๊ณ fs .readdirSync(__dirname) .filter( file => { // linux ์์๋ ์์ . ๊ฐ ๋ถ์ผ๋ฉด ์จ๊นํ์ผ์ return file.indexOf('.') !== 0 && file !== basename && file.slice(-3) === '.js'; }) .forEach( (file) => { const model = require(path.join(__dirname, file)); console.log(file, model.name); db[model.name] = model; model.initiate(sequelize); //model.associate(sequelize); { //console.log(db, modelName); if (db[modelName].associate) { db[modelName].associate(db); } }); module.exports = db;
- 0
- 3
- 274




