-
Notifications
You must be signed in to change notification settings - Fork 48
Implement Automatically Reminder Service #192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mayura-andrew
wants to merge
9
commits into
sef-global:development
Choose a base branch
from
mayura-andrew:automatically-reminder
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
634a324
Update README with Docker setup instructions and clean up init-db script
mayura-andrew b36f4f8
Remove unnecessary blank lines from README
mayura-andrew 7ab1ee6
Clarify Docker setup instructions in README and fix typos
mayura-andrew dc5b47c
Merge branch 'sef-global:development' into docker-fix
mayura-andrew 0e05f3b
Add reminder functionality with cron job and related entities
mayura-andrew dab4c66
Merge branch 'sef-global:development' into automatically-reminder
mayura-andrew b2d64b3
Remove unused reminder router import from admin routes
mayura-andrew d3d1c96
Merge branch 'sef-global:development' into automatically-reminder
mayura-andrew 003215a
Add configurable cron schedule for reminders
mayura-andrew File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,29 @@ | ||
#!/bin/sh | ||
|
||
# This is a script to initialize the database for the first time when the container is started. | ||
# It will wait for the database to be ready before running the migrations. | ||
# Wait for the | ||
|
||
# Wait for the database to be ready | ||
until psql "postgresql://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}" -c '\q'; do | ||
echo "Waiting for database connection..." | ||
sleep 5 | ||
done | ||
|
||
echo "Database is ready. Running migrations..." | ||
|
||
# Run the migrations | ||
npm run sync:db | ||
npm run seed | ||
|
||
# Check if the database is already populated | ||
SEED_CHECK=$(psql "postgresql://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}" -tAc "SELECT COUNT(*) FROM profile;") | ||
|
||
if [ "$SEED_CHECK" -eq "0" ]; then | ||
echo "Database is empty. Running seed script..." | ||
npm run seed | ||
else | ||
echo "Database already contains data. Skipping seed script." | ||
fi | ||
|
||
echo "Migrations complete. Database is ready." | ||
|
||
# Start the application | ||
|
||
npm run dev |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { Column, Entity, ManyToOne } from 'typeorm' | ||
import BaseEntity from './baseEntity' | ||
import { ReminderStatus } from '../enums' | ||
import Mentee from './mentee.entity' | ||
|
||
@Entity('monthly_reminders') | ||
export class MonthlyReminder extends BaseEntity { | ||
@ManyToOne(() => Mentee, (mentee) => mentee.reminders) | ||
mentee!: Mentee | ||
|
||
@Column({ | ||
type: 'enum', | ||
enum: ReminderStatus, | ||
default: ReminderStatus.PENDING | ||
}) | ||
status!: ReminderStatus | ||
|
||
@Column({ type: 'text', nullable: true }) | ||
lastError!: string | ||
|
||
@Column({ type: 'int', default: 0 }) | ||
remindersSent!: number | ||
|
||
@Column({ type: 'timestamp', nullable: true }) | ||
nextReminderDate!: Date | null | ||
|
||
@Column({ type: 'timestamp', nullable: true }) | ||
lastSentDate!: Date | null | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import { type MigrationInterface, type QueryRunner } from 'typeorm' | ||
|
||
export class Reminders1733219895951 implements MigrationInterface { | ||
name = 'Reminders1733219895951' | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query( | ||
`CREATE TABLE "monthly-check-in" ("uuid" uuid NOT NULL DEFAULT uuid_generate_v4(), "created_at" TIMESTAMP NOT NULL DEFAULT now(), "updated_at" TIMESTAMP NOT NULL DEFAULT now(), "title" text NOT NULL, "generalUpdatesAndFeedback" text NOT NULL, "progressTowardsGoals" text NOT NULL, "mediaContentLinks" json, "mentorFeedback" text, "isCheckedByMentor" boolean NOT NULL DEFAULT false, "mentorCheckedDate" TIMESTAMP, "checkInDate" TIMESTAMP NOT NULL DEFAULT now(), "menteeId" uuid, CONSTRAINT "PK_44f1414b858e3eb6b8aacee7fbe" PRIMARY KEY ("uuid"))` | ||
) | ||
await queryRunner.query( | ||
`CREATE TYPE "public"."monthly_reminders_status_enum" AS ENUM('pending', 'sent', 'failed', 'scheduled', 'completed', 'sending')` | ||
) | ||
await queryRunner.query( | ||
`CREATE TABLE "monthly_reminders" ("uuid" uuid NOT NULL DEFAULT uuid_generate_v4(), "created_at" TIMESTAMP NOT NULL DEFAULT now(), "updated_at" TIMESTAMP NOT NULL DEFAULT now(), "status" "public"."monthly_reminders_status_enum" NOT NULL DEFAULT 'pending', "lastError" text, "remindersSent" integer NOT NULL DEFAULT '0', "nextReminderDate" TIMESTAMP, "lastSentDate" TIMESTAMP, "menteeUuid" uuid, CONSTRAINT "PK_f3b22313af4df0cb9cf9c41c681" PRIMARY KEY ("uuid"))` | ||
) | ||
await queryRunner.query( | ||
`CREATE TYPE "public"."mentee_state_enum" AS ENUM('pending', 'rejected', 'approved', 'completed', 'revoked')` | ||
) | ||
await queryRunner.query( | ||
`CREATE TYPE "public"."mentee_status_updated_by_enum" AS ENUM('admin', 'mentor')` | ||
) | ||
await queryRunner.query( | ||
`CREATE TABLE "mentee" ("uuid" uuid NOT NULL DEFAULT uuid_generate_v4(), "created_at" TIMESTAMP NOT NULL DEFAULT now(), "updated_at" TIMESTAMP NOT NULL DEFAULT now(), "state" "public"."mentee_state_enum" NOT NULL DEFAULT 'pending', "status_updated_by" "public"."mentee_status_updated_by_enum", "status_updated_date" TIMESTAMP, "application" json NOT NULL, "certificate_id" uuid, "journal" character varying, "profileUuid" uuid, "mentorUuid" uuid, CONSTRAINT "PK_694f9d45c4a2a5bd2e4158df6a8" PRIMARY KEY ("uuid"))` | ||
) | ||
await queryRunner.query( | ||
`CREATE TYPE "public"."profile_type_enum" AS ENUM('default', 'admin')` | ||
) | ||
await queryRunner.query( | ||
`CREATE TABLE "profile" ("uuid" uuid NOT NULL DEFAULT uuid_generate_v4(), "created_at" TIMESTAMP NOT NULL DEFAULT now(), "updated_at" TIMESTAMP NOT NULL DEFAULT now(), "primary_email" character varying(255) NOT NULL, "first_name" character varying(255) NOT NULL, "last_name" character varying(255), "image_url" character varying(255) NOT NULL, "type" "public"."profile_type_enum" NOT NULL DEFAULT 'default', "password" character varying(255) NOT NULL, CONSTRAINT "UQ_def641b0892f8d810007e362eb0" UNIQUE ("primary_email"), CONSTRAINT "PK_fab5f83a1cc8ebe0076c733fd85" PRIMARY KEY ("uuid"))` | ||
) | ||
await queryRunner.query( | ||
`CREATE TABLE "country" ("uuid" uuid NOT NULL DEFAULT uuid_generate_v4(), "created_at" TIMESTAMP NOT NULL DEFAULT now(), "updated_at" TIMESTAMP NOT NULL DEFAULT now(), "code" character varying NOT NULL, "name" character varying NOT NULL, CONSTRAINT "PK_4e06beff3ecfb1a974312fe536d" PRIMARY KEY ("uuid"))` | ||
) | ||
await queryRunner.query( | ||
`CREATE TYPE "public"."mentor_state_enum" AS ENUM('pending', 'rejected', 'approved')` | ||
) | ||
await queryRunner.query( | ||
`CREATE TABLE "mentor" ("uuid" uuid NOT NULL DEFAULT uuid_generate_v4(), "created_at" TIMESTAMP NOT NULL DEFAULT now(), "updated_at" TIMESTAMP NOT NULL DEFAULT now(), "state" "public"."mentor_state_enum" NOT NULL DEFAULT 'pending', "application" json NOT NULL, "availability" boolean NOT NULL, "categoryUuid" uuid, "profileUuid" uuid, "countryUuid" uuid, CONSTRAINT "PK_50288edf84756228c143608b2be" PRIMARY KEY ("uuid"))` | ||
) | ||
await queryRunner.query( | ||
`CREATE TABLE "category" ("uuid" uuid NOT NULL DEFAULT uuid_generate_v4(), "created_at" TIMESTAMP NOT NULL DEFAULT now(), "updated_at" TIMESTAMP NOT NULL DEFAULT now(), "category" character varying(255) NOT NULL, CONSTRAINT "PK_86ee096735ccbfa3fd319af1833" PRIMARY KEY ("uuid"))` | ||
) | ||
await queryRunner.query( | ||
`CREATE TYPE "public"."email_state_enum" AS ENUM('sent', 'delivered', 'failed')` | ||
) | ||
await queryRunner.query( | ||
`CREATE TABLE "email" ("uuid" uuid NOT NULL DEFAULT uuid_generate_v4(), "created_at" TIMESTAMP NOT NULL DEFAULT now(), "updated_at" TIMESTAMP NOT NULL DEFAULT now(), "recipient" character varying(255) NOT NULL, "subject" character varying(255) NOT NULL, "content" character varying NOT NULL, "state" "public"."email_state_enum" NOT NULL, CONSTRAINT "PK_a6db4f191b9a83ca3c8f4149d13" PRIMARY KEY ("uuid"))` | ||
) | ||
await queryRunner.query( | ||
`ALTER TABLE "monthly-check-in" ADD CONSTRAINT "FK_6de642444085d9599d3f260d566" FOREIGN KEY ("menteeId") REFERENCES "mentee"("uuid") ON DELETE NO ACTION ON UPDATE NO ACTION` | ||
) | ||
await queryRunner.query( | ||
`ALTER TABLE "monthly_reminders" ADD CONSTRAINT "FK_3c019691242e748da81b48747ff" FOREIGN KEY ("menteeUuid") REFERENCES "mentee"("uuid") ON DELETE NO ACTION ON UPDATE NO ACTION` | ||
) | ||
await queryRunner.query( | ||
`ALTER TABLE "mentee" ADD CONSTRAINT "FK_f671cf2220d1bd0621a1a5e92e7" FOREIGN KEY ("profileUuid") REFERENCES "profile"("uuid") ON DELETE NO ACTION ON UPDATE NO ACTION` | ||
) | ||
await queryRunner.query( | ||
`ALTER TABLE "mentee" ADD CONSTRAINT "FK_1fd04826f894fd63a0ce080f6e4" FOREIGN KEY ("mentorUuid") REFERENCES "mentor"("uuid") ON DELETE NO ACTION ON UPDATE NO ACTION` | ||
) | ||
await queryRunner.query( | ||
`ALTER TABLE "mentor" ADD CONSTRAINT "FK_59a1e655aa15be5f068a11f0d23" FOREIGN KEY ("categoryUuid") REFERENCES "category"("uuid") ON DELETE NO ACTION ON UPDATE NO ACTION` | ||
) | ||
await queryRunner.query( | ||
`ALTER TABLE "mentor" ADD CONSTRAINT "FK_ee49a3436192915d20e07378f16" FOREIGN KEY ("profileUuid") REFERENCES "profile"("uuid") ON DELETE NO ACTION ON UPDATE NO ACTION` | ||
) | ||
await queryRunner.query( | ||
`ALTER TABLE "mentor" ADD CONSTRAINT "FK_3302c22eb1636f239d605eb61c3" FOREIGN KEY ("countryUuid") REFERENCES "country"("uuid") ON DELETE NO ACTION ON UPDATE NO ACTION` | ||
) | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query( | ||
`ALTER TABLE "mentor" DROP CONSTRAINT "FK_3302c22eb1636f239d605eb61c3"` | ||
) | ||
await queryRunner.query( | ||
`ALTER TABLE "mentor" DROP CONSTRAINT "FK_ee49a3436192915d20e07378f16"` | ||
) | ||
await queryRunner.query( | ||
`ALTER TABLE "mentor" DROP CONSTRAINT "FK_59a1e655aa15be5f068a11f0d23"` | ||
) | ||
await queryRunner.query( | ||
`ALTER TABLE "mentee" DROP CONSTRAINT "FK_1fd04826f894fd63a0ce080f6e4"` | ||
) | ||
await queryRunner.query( | ||
`ALTER TABLE "mentee" DROP CONSTRAINT "FK_f671cf2220d1bd0621a1a5e92e7"` | ||
) | ||
await queryRunner.query( | ||
`ALTER TABLE "monthly_reminders" DROP CONSTRAINT "FK_3c019691242e748da81b48747ff"` | ||
) | ||
await queryRunner.query( | ||
`ALTER TABLE "monthly-check-in" DROP CONSTRAINT "FK_6de642444085d9599d3f260d566"` | ||
) | ||
await queryRunner.query(`DROP TABLE "email"`) | ||
await queryRunner.query(`DROP TYPE "public"."email_state_enum"`) | ||
await queryRunner.query(`DROP TABLE "category"`) | ||
await queryRunner.query(`DROP TABLE "mentor"`) | ||
await queryRunner.query(`DROP TYPE "public"."mentor_state_enum"`) | ||
await queryRunner.query(`DROP TABLE "country"`) | ||
await queryRunner.query(`DROP TABLE "profile"`) | ||
await queryRunner.query(`DROP TYPE "public"."profile_type_enum"`) | ||
await queryRunner.query(`DROP TABLE "mentee"`) | ||
await queryRunner.query( | ||
`DROP TYPE "public"."mentee_status_updated_by_enum"` | ||
) | ||
await queryRunner.query(`DROP TYPE "public"."mentee_state_enum"`) | ||
await queryRunner.query(`DROP TABLE "monthly_reminders"`) | ||
await queryRunner.query( | ||
`DROP TYPE "public"."monthly_reminders_status_enum"` | ||
) | ||
await queryRunner.query(`DROP TABLE "monthly-check-in"`) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.