Skip to content

Commit

Permalink
Fix bug bottle neck
Browse files Browse the repository at this point in the history
  • Loading branch information
HadesD committed Feb 20, 2022
1 parent ebecf08 commit cc9624f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
4 changes: 2 additions & 2 deletions app_helpers/Auth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ namespace app_helpers
return (getSessionUserId(req) > 0);
}

User user(const drogon::HttpRequestPtr& req)
User user(const drogon::HttpRequestPtr& req, const drogon::orm::DbClientPtr dbClient)
{
auto dbClient = drogon::app().getDbClient();
// auto dbClient = drogon::app().getDbClient();

return drogon::orm::Mapper<User>(dbClient).findByPrimaryKey(getSessionUserId(req));
}
Expand Down
2 changes: 1 addition & 1 deletion app_helpers/Auth.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace app_helpers

bool isLoggedIn(const drogon::HttpRequestPtr& req);

User user(const drogon::HttpRequestPtr& req);
User user(const drogon::HttpRequestPtr& req, const drogon::orm::DbClientPtr dbClient);

void logout(const drogon::HttpRequestPtr& req);
}
Expand Down
16 changes: 10 additions & 6 deletions controllers/StockCtrl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,6 @@ void StockCtrl::create(const HttpRequestPtr &req, std::function<void(const HttpR
}
const auto& reqJson = *reqJsonPtr;

auto dbClient = app().getDbClient()->newTransaction();
orm::Mapper<Stock> stkMapper{dbClient};
Stock stk;

const auto& name = reqJson["name"];
Expand All @@ -201,7 +199,7 @@ void StockCtrl::create(const HttpRequestPtr &req, std::function<void(const HttpR
{
throw std::logic_error("Chưa điền idi");
}
stk.setName(idi.asString());
stk.setIdi(idi.asString());

const auto& sell_price = reqJson["sell_price"];
if (!sell_price.isInt())
Expand Down Expand Up @@ -249,8 +247,13 @@ void StockCtrl::create(const HttpRequestPtr &req, std::function<void(const HttpR
stk.setNote(note.asString());
}

const auto& curUser = app_helpers::Auth::user(req);
stk.setUpdatedUserId(curUser.getValueOfId());
auto dbClient = app().getDbClient()->newTransaction();
orm::Mapper<Stock> stkMapper{dbClient};

// TODO: Fix updated user
// const auto& curUser = app_helpers::Auth::user(req, dbClient);
// stk.setUpdatedUserId(curUser.getValueOfId());
stk.setUpdatedUserId(1);

const auto now = trantor::Date::now();

Expand Down Expand Up @@ -320,7 +323,8 @@ void StockCtrl::create(const HttpRequestPtr &req, std::function<void(const HttpR
Transaction transaction;
transaction.setDescription("Kho #{" + std::to_string(id) + "}: Nhập {"+ std::to_string(stk.getValueOfQuantity()) +"} (VND)");
transaction.setAmount(-(stk.getValueOfQuantity() * stk.getValueOfCostPrice()));
transaction.setCashierId(curUser.getValueOfId());
// TODO: Fix updated user
// transaction.setCashierId(curUser.getValueOfId());
transaction.setPaidDate(trantor::Date::fromDbStringLocal(inout_date.asString()));
orm::Mapper<Transaction>(dbClient).insert(transaction);

Expand Down
10 changes: 5 additions & 5 deletions views/vue/dashboard/pages/stocks/Edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@
>
<a-date-picker
v-model:value="formData.inout_date"
format="YYYY-MM-DD HH:mm:ss"
value-format="YYYY-MM-DD HH:mm:ss"
show-time
type="date"
:disabledDate="disabledLastMonthAndTomorrow"
Expand Down Expand Up @@ -679,8 +679,8 @@ export default defineComponent({
const stockId = this.id;
const request = stockId
? RequestRepository.put
: RequestRepository.post;
? RequestApiRepository.post
: RequestApiRepository.post;
request("/stocks" + (stockId ? `/${stockId}` : ""), {
...this.formData,
inout_date: dayjs(this.formData.inout_date).format(
Expand All @@ -695,8 +695,8 @@ export default defineComponent({
};
}),
})
.then((res) => {
const sData = res.data.data;
.then(data => {
const sData = data.data;
this.$message.success(
stockId
Expand Down

0 comments on commit cc9624f

Please sign in to comment.