Backend Coding
Luwak has a built-in JavaScript engine that provides low-code capabilities. It can implement some business logic with very short codes to make up for the shortcomings of zero code.
Write up to 10 lines
Luwak's goal is to complete each requirement with a maximum of 10 lines of JavaScript code. 10 lines is an empirical value that allows product managers who are not so proficient in JavaScript programming to write and read without stress.
need
Of course, this requires that the requirements be broken down as finely as possible. Large requirements should be broken into several small requirements that can be completed by 10 lines of code. For example, creating an order for an e-commerce company is a big requirement that can be broken down into many smaller requirements:
- User identity verification before creating an order
- Users who are not logged in cannot place orders.
- Blacklisted users cannot place orders
- Products exclusive to new users, only new users can place orders
- Product inspection before creating order
- Products that have been removed from the shelves cannot be sold.
- The inventory quantity is less than the purchase quantity, so the order cannot be placed
- Products limited to regional sales cannot be sold across regions.
This is just a demonstration, the purpose is to demonstrate how to break down large requirements into small requirements. This disassembly solution is just the tip of the iceberg in the real world.
Example
The following code demonstrates the function of automatically salting passwords in the user registration interface. There are 6 lines of business code in total.
// This is mock data
luwakVar.rpcArgs = {
"username": "Mike Tyson",
"password": "1GoodPa$$word!",
"nickName": "coding dog",
}
The following is the business logic:
// Generate a random string as salt
var randomstring = require("randomstring");
luwakVar.rpcArgs["salt"] = randomstring.generate(8);
// Add salt to the user password, and then calculate the hash. The actual stored password is the salted hash.
var CryptoJS = require("crypto-js");
luwakVar.rpcArgs["password"] = CryptoJS.MD5(luwakVar.rpcArgs["salt"] + luwakVar.rpcArgs["password"])
//Insert into database
var primaryKeyId = luwak.dao("passport.account.add", luwakVar.rpcArgs)
console.log("New user id: ", primaryKeyId);
//return results
luwak.returnResult(primaryKeyId)