Skip to content

Commit

Permalink
feat: wallet page 50% done.
Browse files Browse the repository at this point in the history
  • Loading branch information
conradbekondo committed Jan 4, 2025
2 parents 477416a + 7856fbb commit 1ddec83
Show file tree
Hide file tree
Showing 75 changed files with 10,765 additions and 593 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/branch-deploys.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: Branch Deploys for Netlify
name: Staging Deploy

on:
push:
branches:
- next
paths:
- "netlify/functions/**/*.*"
- "server/functions/**/*.*"
- "src/**/*.*"
- "lib/**/*.*"
- "netlify.toml"
Expand Down Expand Up @@ -45,6 +45,6 @@ jobs:
if: steps.setup-cache.outputs.cache-hit != 'true'
run: pnpm i
- name: Migrate Database Schema
run: pnpm migrate.ci
run: pnpm migrate.staging
- name: Build ⚙️ & Deploy ⬆️
run: netlify deploy --alias="${{ github.ref_name }}" --build --context deploy-preview --message="${{ github.event.head_commit.message }}"
run: netlify deploy --alias="staging" --build --context deploy-preview --message="${{ github.event.head_commit.message }}"
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"type": "chrome",
"request": "launch",
"preLaunchTask": "npm: start",
"url": "http://localhost:4200/"
"url": "http://localhost:8888/"
},
{
"name": "ng test",
Expand Down
17 changes: 17 additions & 0 deletions db/log-writer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { LogWriter } from 'drizzle-orm/logger';
import pino, { Logger } from 'pino';
export class PinoWriter implements LogWriter {
private logger: Logger;

write(message: string) {
this.logger.info(message);
}

constructor(transport?: any) {
try {
this.logger = pino({ transport, name: 'drizzle' });
} catch (e) {
throw e;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
CREATE TYPE "public"."payment_methods" AS ENUM('momo');--> statement-breakpoint
CREATE TYPE "public"."transaction_status" AS ENUM('pending', 'cancelled', 'complete');--> statement-breakpoint
CREATE TABLE "campaign_publications" (
"id" bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "campaign_publications_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START WITH 1 CACHE 1),
"created_at" timestamp DEFAULT now(),
Expand Down Expand Up @@ -29,6 +31,41 @@ CREATE TABLE "categories" (
"image" varchar(500)
);
--> statement-breakpoint
CREATE TABLE "account_transactions" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"payment_method" "payment_methods" NOT NULL,
"status" "transaction_status" NOT NULL,
"external_transaction_id" varchar(400),
"recorded_at" timestamp DEFAULT now(),
"completed_at" timestamp,
"cancelled_at" timestamp,
"value" real NOT NULL,
"currency" varchar(10) NOT NULL,
"payment_method_extras" json,
"inbound" boolean NOT NULL
);
--> statement-breakpoint
CREATE TABLE "wallet_transactions" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"wallet" uuid NOT NULL,
"value" bigint NOT NULL,
"from" uuid NOT NULL,
"to" uuid NOT NULL,
"recorded_at" timestamp DEFAULT now(),
"completed_at" timestamp,
"cancelled_at" timestamp,
"status" "transaction_status" DEFAULT 'pending',
"account_transaction" uuid
);
--> statement-breakpoint
CREATE TABLE "wallets" (
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
"owned_by" bigint NOT NULL,
"created_at" timestamp DEFAULT now(),
"updated_at" timestamp DEFAULT now(),
"starting_balance" bigint DEFAULT 0
);
--> statement-breakpoint
CREATE TABLE "federated_credentials" (
"id" varchar(255) PRIMARY KEY NOT NULL,
"provider" varchar(255) NOT NULL,
Expand All @@ -38,17 +75,22 @@ CREATE TABLE "federated_credentials" (
);
--> statement-breakpoint
CREATE TABLE "users" (
"id" bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "users_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START WITH 1 CACHE 1),
"id" bigint PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "users_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 9223372036854775807 START WITH 100 CACHE 1),
"created_at" timestamp DEFAULT now(),
"updated_at" timestamp DEFAULT now(),
"names" varchar(100) NOT NULL,
"image_url" varchar(255),
"email" varchar(100) NOT NULL,
"dob" date,
"phone" varchar(255),
"credentials" varchar NOT NULL
"credentials" varchar
);
--> statement-breakpoint
ALTER TABLE "campaign_publications" ADD CONSTRAINT "campaign_publications_campaign_campaigns_id_fk" FOREIGN KEY ("campaign") REFERENCES "public"."campaigns"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "campaigns" ADD CONSTRAINT "campaigns_created_by_users_id_fk" FOREIGN KEY ("created_by") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "wallet_transactions" ADD CONSTRAINT "wallet_transactions_wallet_wallets_id_fk" FOREIGN KEY ("wallet") REFERENCES "public"."wallets"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "wallet_transactions" ADD CONSTRAINT "wallet_transactions_from_wallets_id_fk" FOREIGN KEY ("from") REFERENCES "public"."wallets"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "wallet_transactions" ADD CONSTRAINT "wallet_transactions_to_wallets_id_fk" FOREIGN KEY ("to") REFERENCES "public"."wallets"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "wallet_transactions" ADD CONSTRAINT "wallet_transactions_account_transaction_account_transactions_id_fk" FOREIGN KEY ("account_transaction") REFERENCES "public"."account_transactions"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "wallets" ADD CONSTRAINT "wallets_owned_by_users_id_fk" FOREIGN KEY ("owned_by") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "users" ADD CONSTRAINT "users_credentials_federated_credentials_id_fk" FOREIGN KEY ("credentials") REFERENCES "public"."federated_credentials"("id") ON DELETE no action ON UPDATE no action;
3 changes: 3 additions & 0 deletions db/migrations/0001_massive_king_cobra.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE "wallet_transactions" DROP CONSTRAINT "wallet_transactions_wallet_wallets_id_fk";
--> statement-breakpoint
ALTER TABLE "wallet_transactions" DROP COLUMN "wallet";
9 changes: 9 additions & 0 deletions db/migrations/0002_stiff_sprite.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE TYPE "public"."wallet_transaction_type" AS ENUM('funding', 'reward', 'withdrawal');--> statement-breakpoint
ALTER TABLE "wallet_transactions" ADD COLUMN "type" "wallet_transaction_type" NOT NULL;--> statement-breakpoint
CREATE VIEW "public"."vw_funding_balances" AS (select "wallets"."id", "wallets"."starting_balance" + SUM(
CASE
WHEN ("wallet_transactions"."from" = "wallets"."id" and "wallet_transactions"."type" = 'funding' and "wallet_transactions"."status" = 'complete') THEN -"wallet_transactions"."value"
WHEN ("wallet_transactions"."to" = "wallets"."id" and "wallet_transactions"."type" = 'funding' and "wallet_transactions"."status" = 'complete') THEN "wallet_transactions"."value"
ELSE 0
END
)::BIGINT as "balance", "wallets"."owned_by", "users"."names" from "wallets" left join "wallet_transactions" on ("wallets"."id" = "wallet_transactions"."from" or "wallets"."id" = "wallet_transactions"."to") left join "users" on "wallets"."owned_by" = "users"."id" group by "wallets"."id", "wallets"."owned_by", "users"."names");
7 changes: 7 additions & 0 deletions db/migrations/0003_youthful_rattler.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE VIEW "public"."vw_reward_balances" AS (select "wallets"."id", "wallets"."starting_balance" + SUM(
CASE
WHEN ("wallet_transactions"."from" = "wallets"."id" and "wallet_transactions"."type" = 'reward' and "wallet_transactions"."status" = 'complete') THEN -"wallet_transactions"."value"
WHEN ("wallet_transactions"."to" = "wallets"."id" and "wallet_transactions"."type" = 'reward' and "wallet_transactions"."status" = 'complete') THEN "wallet_transactions"."value"
ELSE 0
END
)::BIGINT as "balance", "wallets"."owned_by", "users"."names" from "wallets" left join "wallet_transactions" on ("wallets"."id" = "wallet_transactions"."from" or "wallets"."id" = "wallet_transactions"."to") left join "users" on "wallets"."owned_by" = "users"."id" group by "wallets"."id", "wallets"."owned_by", "users"."names");
16 changes: 16 additions & 0 deletions db/migrations/0004_bright_abomination.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
DROP VIEW "public"."vw_funding_balances";--> statement-breakpoint
DROP VIEW "public"."vw_reward_balances";--> statement-breakpoint
CREATE VIEW "public"."vw_funding_balances" AS (select "wallets"."id", "wallets"."starting_balance" + SUM(
CASE
WHEN ("wallet_transactions"."from" = "wallets"."id" and "wallet_transactions"."type" = 'funding' and "wallet_transactions"."status" = 'complete') THEN -"wallet_transactions"."value"
WHEN ("wallet_transactions"."to" = "wallets"."id" and "wallet_transactions"."type" = 'funding' and "wallet_transactions"."status" = 'complete') THEN "wallet_transactions"."value"
ELSE 0
END
)::BIGINT as "balance", "wallets"."owned_by" from "wallets" left join "wallet_transactions" on ("wallets"."id" = "wallet_transactions"."from" or "wallets"."id" = "wallet_transactions"."to") left join "users" on "wallets"."owned_by" = "users"."id" group by "wallets"."id", "wallets"."owned_by");--> statement-breakpoint
CREATE VIEW "public"."vw_reward_balances" AS (select "wallets"."id", "wallets"."starting_balance" + SUM(
CASE
WHEN ("wallet_transactions"."from" = "wallets"."id" and "wallet_transactions"."type" = 'reward' and "wallet_transactions"."status" = 'complete') THEN -"wallet_transactions"."value"
WHEN ("wallet_transactions"."to" = "wallets"."id" and "wallet_transactions"."type" = 'reward' and "wallet_transactions"."status" = 'complete') THEN "wallet_transactions"."value"
ELSE 0
END
)::BIGINT as "balance", "wallets"."owned_by" from "wallets" left join "wallet_transactions" on ("wallets"."id" = "wallet_transactions"."from" or "wallets"."id" = "wallet_transactions"."to") left join "users" on "wallets"."owned_by" = "users"."id" group by "wallets"."id", "wallets"."owned_by");
Loading

0 comments on commit 1ddec83

Please sign in to comment.