From d6ad90fb2de0152ac1640addda6eba930dacf2a1 Mon Sep 17 00:00:00 2001 From: JUNU Date: Tue, 9 Jun 2026 15:42:21 +0900 Subject: [PATCH 1/5] delelte getDb --- src/models/userModel.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/models/userModel.js b/src/models/userModel.js index 2a8d5e7..ad41b90 100644 --- a/src/models/userModel.js +++ b/src/models/userModel.js @@ -91,10 +91,6 @@ async function initDb(db) { return db; } -function getDb() { - return usersDb; -} - async function findById(user_id) { return await usersDb.get("SELECT * FROM users WHERE user_id = ?", [user_id]); } @@ -174,7 +170,7 @@ async function decreaseWillIfEnough(user_id, price) { async function increaseWillAfterPost(calculatedWillReward, user_id){ - const result = await getDb().run( + const result = await usersDb.run( `UPDATE users SET will_balance = will_balance + ? WHERE user_id = ?`, [calculatedWillReward, user_id]); } From 9b456d5979f9607e765941f6bb10dba4ee0fdb87 Mon Sep 17 00:00:00 2001 From: JUNU Date: Tue, 9 Jun 2026 15:53:25 +0900 Subject: [PATCH 2/5] refactor getting user id --- src/controllers/postController.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/controllers/postController.js b/src/controllers/postController.js index af726da..589842d 100644 --- a/src/controllers/postController.js +++ b/src/controllers/postController.js @@ -33,8 +33,8 @@ async function getById(req, res){ // req.body would be undefined. async function create(req, res) { try { - const { user_id, title, content, image_url, tag, visibility, word_count, - will_reward, created_at, updated_at } = req.body; + const user_id = req.user.user_id; + const {title, content, image_url, tag, visibility, will_reward} = req.body; // Basic validation: required fields must be present. // Without this, an INSERT with NULL would fail at the database level // because of the NOT NULL constraints we defined in db.js. @@ -43,17 +43,14 @@ async function create(req, res) { !title || !content || !tag || - !visibility || - //word_count === undefined || - // will_reward === undefined || - created_at == null || - updated_at == null + !visibility ) { return res.status(400).json({ error: "Missing required fields" }); } const countTheWords = (str) => {return str.trim() .split(/\s+/).length;} const wordCount = countTheWords(content); - + const created_at = new Date().toISOString().split("T")[0]; + const updated_at = new Date().toISOString().split("T")[0]; const calculatedWillReward = Math.round(wordCount / 10); // TRANSACTION shizzle implementieren !! -> implement postService.js !! From 107af11ee11ae7bc533c5c0b8b7670098ab99988 Mon Sep 17 00:00:00 2001 From: JUNU Date: Tue, 9 Jun 2026 15:58:02 +0900 Subject: [PATCH 3/5] make responses uniform with document --- src/controllers/postController.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/controllers/postController.js b/src/controllers/postController.js index 589842d..2746784 100644 --- a/src/controllers/postController.js +++ b/src/controllers/postController.js @@ -7,7 +7,7 @@ async function getAll(req, res){ const user_id = Number(req.user.user_id); const posts = await postModel.getAll(user_id); //if(!posts || posts.length === 0) return res.status(404).json("no Posts found"); - res.status(200).json(posts); + res.status(200).json({"posts": posts}); } catch (err){ console.error(err); res.status(err.statusCode || 500).json({error: err.message}); @@ -20,7 +20,7 @@ async function getById(req, res){ const post_id = Number(req.params.id); const post = await postModel.findById(post_id, user_id); //if(!post) return res.status(404).json({error: "Post not found"}); - return res.status(200).json(post); + return res.status(200).json({ "post": post}); } catch (err) { console.error(err); res.status(err.statusCode || 500).json({error: err.message}); @@ -58,7 +58,7 @@ async function create(req, res) { userModel.increaseWillAfterPost(calculatedWillReward, user_id); - res.status(201).json(newPost); + res.status(201).json({"post" : newPost}); } catch (err) { console.error(err); res.status(500).json({ error: "Database error" }); From 6e3510354e46fd641a9d828dc262b82b3c4c4bac Mon Sep 17 00:00:00 2001 From: JUNU Date: Tue, 9 Jun 2026 16:11:15 +0900 Subject: [PATCH 4/5] integrate --- src/controllers/shopController.js | 2 +- src/services/eggService.js | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/controllers/shopController.js b/src/controllers/shopController.js index 5a94e52..1753adf 100644 --- a/src/controllers/shopController.js +++ b/src/controllers/shopController.js @@ -39,7 +39,7 @@ async function getAll(req, res) { if(!items) { return res.status(404).json({error: "Shop Items not found"}); } - return res.status(200).json(items); + return res.status(200).json({"items": items}); } catch(err){ res.status(500).json({ error: `Database error : ${err}`}); diff --git a/src/services/eggService.js b/src/services/eggService.js index 98ce50d..77521d4 100644 --- a/src/services/eggService.js +++ b/src/services/eggService.js @@ -39,16 +39,18 @@ async function equip({ user_id, item_id }) { // if there is an item which is already equipped, unequip if (prior != null && prior != item_id) { let priorInventory = await userItemModel.findByIds(user_id, prior); - + let priorItem = await shopItemModel.findById(prior); if (priorInventory) { priorInventory.is_equipped = 0; await userItemModel.update(priorInventory); } + applyItemEffect(egg, priorItem, 0); } - if (prior != item_id){ - applyItemEffect(egg, await shopItemModel.findById(prior), 0); + + if(prior != item_id){ applyItemEffect(egg, item, 1); } + egg[`active_${itemType}_id`] = itemInventory.item_id; itemInventory.is_equipped = 1; // equip item @@ -66,7 +68,6 @@ async function equip({ user_id, item_id }) { } - async function unequip({ user_id, item_id }) { let egg = await eggModel.findById(user_id); if (!egg) { From c3d18936ab6a598e916de4b0b1a68956a307cc2e Mon Sep 17 00:00:00 2001 From: JUNU Date: Tue, 9 Jun 2026 16:23:12 +0900 Subject: [PATCH 5/5] refactor response --- docs/api/openapi.yaml | 22 +++++++++++-- package-lock.json | 73 ++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 88 insertions(+), 7 deletions(-) diff --git a/docs/api/openapi.yaml b/docs/api/openapi.yaml index 198b003..d7578db 100644 --- a/docs/api/openapi.yaml +++ b/docs/api/openapi.yaml @@ -324,6 +324,14 @@ components: type: integer example: 3 + QuestClaimRequest: + type: object + required: [post_id] + properties: + post_id: + type: integer + example: 3 + CreatePostRequest: type: object required: [title, content, tag, visibility] @@ -438,7 +446,7 @@ components: properties: userQuest: $ref: '#/components/schemas/UserQuest' - willBalance: + will_balance_of_user: type: integer example: 130 @@ -472,10 +480,12 @@ components: InventoryResponse: type: object properties: + userItems: + type: array + $ref: '#/components/schemas/UserItem' items: type: array - items: - $ref: '#/components/schemas/InventoryItem' + $ref: '#/components/schemas/ShopItem' paths: # 0. SYSTEM CHECK @@ -782,6 +792,12 @@ paths: post: summary: Claim completed quest reward tags: [Quest] + requestBody: + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/QuestClaimRequest' security: - bearerAuth: [] parameters: diff --git a/package-lock.json b/package-lock.json index 13a5e4a..44d0422 100644 --- a/package-lock.json +++ b/package-lock.json @@ -572,9 +572,9 @@ "license": "MIT" }, "node_modules/@emnapi/wasi-threads": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-1.2.1.tgz", - "integrity": "sha512-uTII7OYF+/Mes/MrcIOYp5yOtSMLBWSIoLPpcgwipoiKbli6k322tcoFsxoIIxPDqW01SQGAgko4EzZi2BNv2w==", + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-1.2.2.tgz", + "integrity": "sha512-c95qOXkHdydNKhscBTebqEC1CVAZpyqOfVfBzQ1qgzyl3gfeldUjIggDbIZgDKsHLgnsM+igH7TJ/eAasaVuMA==", "dev": true, "license": "MIT", "optional": true, @@ -1525,6 +1525,40 @@ "node": ">=14.0.0" } }, + "node_modules/@unrs/resolver-binding-wasm32-wasi/node_modules/@emnapi/core": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/@emnapi/core/-/core-1.10.0.tgz", + "integrity": "sha512-yq6OkJ4p82CAfPl0u9mQebQHKPJkY7WrIuk205cTYnYe+k2Z8YBh11FrbRG/H6ihirqcacOgl2BIO8oyMQLeXw==", + "dev": true, + "license": "MIT", + "optional": true, + "dependencies": { + "@emnapi/wasi-threads": "1.2.1", + "tslib": "^2.4.0" + } + }, + "node_modules/@unrs/resolver-binding-wasm32-wasi/node_modules/@emnapi/runtime": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.10.0.tgz", + "integrity": "sha512-ewvYlk86xUoGI0zQRNq/mC+16R1QeDlKQy21Ki3oSYXNgLb45GV1P6A0M+/s6nyCuNDqe5VpaY84BzXGwVbwFA==", + "dev": true, + "license": "MIT", + "optional": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, + "node_modules/@unrs/resolver-binding-wasm32-wasi/node_modules/@emnapi/wasi-threads": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-1.2.1.tgz", + "integrity": "sha512-uTII7OYF+/Mes/MrcIOYp5yOtSMLBWSIoLPpcgwipoiKbli6k322tcoFsxoIIxPDqW01SQGAgko4EzZi2BNv2w==", + "dev": true, + "license": "MIT", + "optional": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, "node_modules/@unrs/resolver-binding-win32-arm64-msvc": { "version": "1.12.2", "resolved": "https://registry.npmjs.org/@unrs/resolver-binding-win32-arm64-msvc/-/resolver-binding-win32-arm64-msvc-1.12.2.tgz", @@ -4843,12 +4877,20 @@ "integrity": "sha512-A/AGNMFN3c8bOlvV9RreMdrv7jsmF9XIfDeCd87+I8RNg6s78BhJxMu69NEMHBSJFxKidViTEdruRwEk/WIKqA==", "license": "MIT" }, + "node_modules/picocolors": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", + "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==", + "dev": true, + "license": "ISC" + }, "node_modules/picomatch": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.4.tgz", "integrity": "sha512-QP88BAKvMam/3NxH6vj2o21R6MjxZUAd6nlwAS/pnGvN9IVLocLHxGYIzFhg6fUQ+5th6P4dv4eW9jX3DSIj7A==", + "devOptional": true, "license": "MIT", - "optional": true, + "peer": true, "engines": { "node": ">=12" }, @@ -4856,6 +4898,29 @@ "url": "https://github.com/sponsors/jonschlinkert" } }, + "node_modules/pirates": { + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/pirates/-/pirates-4.0.7.tgz", + "integrity": "sha512-TfySrs/5nm8fQJDcBDuUng3VOUKsd7S+zqvbOTiGXHfxX4wK31ard+hoNuvkicM/2YFzlpDgABOevKSsB4G/FA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 6" + } + }, + "node_modules/pkg-dir": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-4.2.0.tgz", + "integrity": "sha512-HRDzbaKjC+AOWVXxAU/x54COGeIv9eb+6CkDSQoNTt4XyWoIJvuPsXizxu/Fr23EiekbtZwmh1IcIG/l/a10GQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "find-up": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/prebuild-install": { "version": "7.1.3", "resolved": "https://registry.npmjs.org/prebuild-install/-/prebuild-install-7.1.3.tgz",