Skip to content

Instantly share code, notes, and snippets.

View ktutnik's full-sized avatar

Ketut Sandiarsa ktutnik

  • VetVision
  • Indonesia
View GitHub Profile
@ktutnik
ktutnik / signing-git-commits.md
Created March 31, 2023 09:38 — forked from phortuin/signing-git-commits.md
Set up a GPG key for signing Git commits on MacOS (M1)

Based on this blogpost.

To sign Git commits, you need a gpg key. GPG stands for GNU Privacy Guard and is the de facto implementation of the OpenPGP message format. PGP stands for ‘Pretty Good Privacy’ and is a standard to sign and encrypt messages.

Setting up

Install with Homebrew:

$ brew install gpg
@ktutnik
ktutnik / aws-hosting.sh
Last active August 23, 2021 06:40
Shell script to create static website hosting on AWS S3 + CloudFront
#!/bin/bash
set -e
REGION="ap-southeast-1"
if [ -z "$1" ]
then
echo "The bucket name is not specified"
exit 1
@genericController(c => {
// Only Shop Owner can modify and delete the shop data
c.methods("Delete", "Patch", "Put").authorize("ShopOwner")
})
@Entity()
export class Shop extends EntityBase {
@val.required()
@Column()
name: string
User management /api/users
Shop management /api/shops
Shop User management /api/shops/{shopId}/users
Shop Product management /api/shops/{shopsId}/products
Image management /api/images
User Shops list /api/shops
Products list /api/products
Shopping Cart /api/shopping-carts
Shopping Cart Item /api/shopping-carts/{cartId}/items
Shopping Cart Checkout /api/shopping-carts/checkout
import { GenericController } from "@plumier/typeorm"
import { Context } from "koa"
export class ProductsController extends GenericController(Product) {
// override save method (POST /path)
save(data: Product, ctx: Context) {
// add your custom logic here
const result = super.save(data, ctx)
// add your custom logic here
@genericController()
@Entity()
export class Shop {
@PrimaryGeneratedColumn()
id: number
/** ------ other properties ------ **/
@authorize.readonly()
@Column()
@Entity()
export class Product {
@PrimaryGeneratedColumn()
id: number;
/** ------ other properties ------ **/
@ManyToOne(x => Category)
category:Category
}
@Entity()
export class Shop {
@PrimaryGeneratedColumn()
id: number
/** ------ other properties ------ **/
@genericController()
@OneToMany(x => Product, x => x.shop)
products:Product[]
authPolicy()
.register("ShopOwner", ctx => {
// ctx.user is claims of JWT token
// from Authorization request header
return ctx.user?.role === "ShopOwner"
})
// chain to register another policy
.register("Staff", ctx => {
return ctx.user?.role === "Staff"
})
@genericController(c => {
c.mutators().authorize("ShopOwner", "Staff")
})
@Entity()
export class Product {
@PrimaryGeneratedColumn()
id: number;
@val.required()
@Column()