Add branches management module with database schema and validation
- Introduced `BranchesModule` to manage organizational branches, including read and write controllers. - Created database migrations for the `branches` table, including constraints and unique indexes. - Implemented validation for branch fields such as name, code, and address with corresponding utility functions. - Developed service and repository layers for handling branch data operations. - Added unit tests for the branches service, repository, and controllers to ensure functionality and correctness. - Updated application module to include the new `BranchesModule` for better organization.
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
CREATE TABLE "branches" (
|
||||
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
||||
"code" varchar(16) NOT NULL,
|
||||
"name" varchar(64) NOT NULL,
|
||||
"phone" text NOT NULL,
|
||||
"address" text NOT NULL,
|
||||
"latitude" double precision,
|
||||
"longitude" double precision,
|
||||
"working_days_start" text NOT NULL,
|
||||
"working_days_end" text NOT NULL,
|
||||
"working_hours_start" varchar(5) NOT NULL,
|
||||
"working_hours_end" varchar(5) NOT NULL,
|
||||
"nfc_id" text,
|
||||
"division_id" uuid,
|
||||
"status" text DEFAULT 'draft' NOT NULL,
|
||||
"created_at" bigint NOT NULL,
|
||||
"updated_at" bigint NOT NULL,
|
||||
"created_by" uuid NOT NULL,
|
||||
"updated_by" uuid NOT NULL
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "branches" ADD CONSTRAINT "branches_division_id_divisions_id_fk" FOREIGN KEY ("division_id") REFERENCES "public"."divisions"("id") ON DELETE restrict ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "branches" ADD CONSTRAINT "branches_created_by_users_id_fk" FOREIGN KEY ("created_by") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
ALTER TABLE "branches" ADD CONSTRAINT "branches_updated_by_users_id_fk" FOREIGN KEY ("updated_by") REFERENCES "public"."users"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "branches_code_unique" ON "branches" USING btree ("code");--> statement-breakpoint
|
||||
CREATE UNIQUE INDEX "branches_nfc_id_unique" ON "branches" USING btree ("nfc_id");
|
||||
--> statement-breakpoint
|
||||
INSERT INTO "privilege_keys" ("code", "label", "sort_order") VALUES
|
||||
('CONFIGURATION.BRANCH', 'Branches', 4);
|
||||
Reference in New Issue
Block a user