feat: gift journeys

This commit is contained in:
Abdalhamid Alhamad
2024-12-22 16:34:02 +03:00
parent 4cef58580e
commit 5e9e83cb74
28 changed files with 656 additions and 1 deletions

View File

@ -0,0 +1,30 @@
import {
BaseEntity,
Column,
CreateDateColumn,
Entity,
JoinColumn,
ManyToOne,
PrimaryGeneratedColumn,
UpdateDateColumn,
} from 'typeorm';
import { Gift } from './gift.entity';
@Entity('gift_redemptions')
export class GiftRedemption extends BaseEntity {
@PrimaryGeneratedColumn('uuid')
id!: string;
@Column({ type: 'uuid', name: 'gift_id' })
giftId!: string;
@ManyToOne(() => Gift, (gift) => gift.redemptions, { onDelete: 'CASCADE' })
@JoinColumn({ name: 'gift_id' })
gift!: Gift;
@CreateDateColumn({ name: 'created_at', type: 'timestamp with time zone', default: () => 'CURRENT_TIMESTAMP' })
createdAt!: Date;
@UpdateDateColumn({ name: 'updated_at', type: 'timestamp with time zone', default: () => 'CURRENT_TIMESTAMP' })
updatedAt!: Date;
}

View File

@ -0,0 +1,25 @@
import { BaseEntity, Column, CreateDateColumn, Entity, JoinColumn, OneToOne, PrimaryGeneratedColumn } from 'typeorm';
import { GiftColor, GiftReplyStatus } from '../enums';
import { Gift } from './gift.entity';
@Entity('gift_replies')
export class GiftReply extends BaseEntity {
@PrimaryGeneratedColumn('uuid')
id!: string;
@Column({ type: 'varchar', name: 'status', default: GiftReplyStatus.PENDING })
status!: GiftReplyStatus;
@Column({ type: 'varchar', name: 'color' })
color!: GiftColor;
@Column({ type: 'uuid', name: 'gift_id' })
giftId!: string;
@OneToOne(() => Gift, (gift) => gift.reply, { onDelete: 'CASCADE' })
@JoinColumn({ name: 'gift_id' })
gift!: Gift;
@CreateDateColumn({ name: 'created_at', type: 'timestamp with time zone', default: () => 'CURRENT_TIMESTAMP' })
createdAt!: Date;
}

View File

@ -0,0 +1,83 @@
import {
Column,
CreateDateColumn,
Entity,
JoinColumn,
ManyToOne,
OneToMany,
OneToOne,
PrimaryGeneratedColumn,
UpdateDateColumn,
} from 'typeorm';
import { Document } from '~/document/entities';
import { Guardian } from '~/guardian/entities/guradian.entity';
import { Junior } from '~/junior/entities';
import { GiftColor, GiftStatus } from '../enums';
import { GiftRedemption } from './gift-redemption.entity';
import { GiftReply } from './gift-reply.entity';
@Entity('gift')
export class Gift {
@PrimaryGeneratedColumn('uuid')
id!: string;
@Column({ type: 'varchar', length: 255, name: 'name' })
name!: string;
@Column({ type: 'text', name: 'description' })
description!: string;
@Column({ type: 'varchar', name: 'color' })
color!: GiftColor;
@Column({
type: 'decimal',
name: 'amount',
precision: 10,
scale: 3,
transformer: {
to: (value: number) => value,
from: (value: string) => parseFloat(value),
},
})
amount!: number;
@Column({ type: 'varchar', name: 'status', default: GiftStatus.AVAILABLE })
status!: GiftStatus;
@Column({ type: 'timestamp with time zone', name: 'redeemed_at', nullable: true })
redeemedAt!: Date | null;
@Column({ type: 'uuid', name: 'giver_id' })
giverId!: string;
@Column({ type: 'uuid', name: 'image_id' })
imageId!: string;
@Column({ type: 'uuid', name: 'recipient_id' })
recipientId!: string;
@ManyToOne(() => Guardian, (guardian) => guardian.gifts)
@JoinColumn({ name: 'giver_id' })
giver!: Guardian;
@ManyToOne(() => Junior, (junior) => junior.gifts)
@JoinColumn({ name: 'recipient_id' })
recipient!: Junior;
@ManyToOne(() => Document, (document) => document.gifts)
@JoinColumn({ name: 'image_id' })
image!: Document;
@OneToMany(() => GiftRedemption, (giftRedemption) => giftRedemption.gift, { cascade: true })
redemptions!: GiftRedemption[];
@OneToOne(() => GiftReply, (giftReply) => giftReply.gift, { cascade: true })
reply?: GiftReply;
@CreateDateColumn({ name: 'created_at', type: 'timestamp with time zone', default: () => 'CURRENT_TIMESTAMP' })
createdAt!: Date;
@UpdateDateColumn({ name: 'updated_at', type: 'timestamp with time zone', default: () => 'CURRENT_TIMESTAMP' })
updatedAt!: Date;
}

View File

@ -0,0 +1,3 @@
export * from './gift-redemption.entity';
export * from './gift-reply.entity';
export * from './gift.entity';