Wrapping up
Congratulations, you are now able to create products and manage your stock! Feel free to continue from here and build out the schema for your use case or just open up and build out an existing project!
As you have seen, tools heavily utilise all types of actions in Keel. A great starting point when thinking about tools is to create an action of each type per each model and go from there. Happy building!
Final schema
The final schema for our inventory management tool is below.
model Product {
fields {
name Text
description Text?
imageUrl Text?
stock StockItem[]
}
actions {
get getProduct(id)
list listProducts()
list listProductsWhereStock(stock.id)
create createProduct() with (name, description?, imageUrl?, stock.quantity, stock.location.id)
}
@permission(
expression: ctx.isAuthenticated,
actions: [list, create, get]
)
}
model StockItem {
fields {
product Product
quantity Number
location StockLocation
}
actions {
create createStockItem() with (quantity, product.id, location.id)
list listStockItems(product.id)
update updateStockItem(id) with (quantity)
delete deleteStockItem(id)
get getStockItem(id)
}
@permission(
expression: ctx.isAuthenticated,
actions: [list, update, delete, get]
)
}
model StockLocation {
fields {
name Text @unique
items StockItem[]
}
actions {
list listStockLocations()
create createStockLocation() with (name)
update updateStockLocation(id) with (name)
delete deleteStockLocation(name)
get getStockLocation(id)
}
@permission(
expression: ctx.isAuthenticated,
actions: [list, create, update, delete, get]
)
}