Skip to content

Commit

Permalink
Merge pull request #8 from cofinder-team/develop
Browse files Browse the repository at this point in the history
release: v23.08.12
  • Loading branch information
lsjbh45 committed Aug 12, 2023
2 parents a25f606 + ae20e25 commit 23bb673
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/entities/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { AlertTarget } from './alert/target.entity';
import { Deal } from './deal.entity';
import { Item } from './item.entity';
import { ItemIpad } from './item/ipad.entity';
import { ItemIphone } from './item/iphone.entity';
import { ItemMacbook } from './item/macbook.entity';
import { CoupangLog } from './log/coupang.entity';
import { Model } from './model.entity';
Expand All @@ -14,6 +15,7 @@ export {
Item,
ItemMacbook,
ItemIpad,
ItemIphone,
Model,
CoupangLog,
User,
Expand Down
8 changes: 8 additions & 0 deletions src/entities/item.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Deal } from './deal.entity';
import { AlertTarget } from './alert/target.entity';
import { ItemMacbook } from './item/macbook.entity';
import { ItemIpad } from './item/ipad.entity';
import { ItemIphone } from './item/iphone.entity';

@Entity({ schema: 'macguider', name: 'item' })
export class Item extends BaseEntity {
Expand All @@ -35,6 +36,13 @@ export class Item extends BaseEntity {
])
ipad: ItemIpad;

@OneToOne(() => ItemIphone, (ItemIphone) => ItemIphone.item)
@JoinColumn([
{ name: 'type', referencedColumnName: 'type' },
{ name: 'id', referencedColumnName: 'id' },
])
iphone: ItemIphone;

@OneToMany(() => Vendor, (vendor) => vendor.item)
@JoinColumn([
{ name: 'type', referencedColumnName: 'type' },
Expand Down
27 changes: 27 additions & 0 deletions src/entities/item/iphone.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Column, Entity, JoinColumn, ManyToOne, OneToOne } from 'typeorm';
import { ItemDetailEntity } from './detall.entity';
import { Model } from '../model.entity';
import { Item } from '../item.entity';

@Entity({ schema: 'macguider', name: 'item_iphone' })
export class ItemIphone extends ItemDetailEntity {
@Column()
modelSuffix: string;

@Column()
phoneStorage: string;

@ManyToOne(() => Model, (model) => model.iphoneItems)
@JoinColumn([
{ name: 'type', referencedColumnName: 'type' },
{ name: 'model', referencedColumnName: 'id' },
])
modelEntity: Model;

@OneToOne(() => Item, (item) => item.iphone)
@JoinColumn([
{ name: 'type', referencedColumnName: 'type' },
{ name: 'id', referencedColumnName: 'id' },
])
item: Item;
}
8 changes: 8 additions & 0 deletions src/entities/model.entity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Column, Entity, JoinColumn, OneToMany, PrimaryColumn } from 'typeorm';
import { ItemIpad } from './item/ipad.entity';
import { ItemMacbook } from './item/macbook.entity';
import { ItemIphone } from './item/iphone.entity';

@Entity({ schema: 'macguider', name: 'model' })
export class Model {
Expand All @@ -26,4 +27,11 @@ export class Model {
{ name: 'id', referencedColumnName: 'model' },
])
ipadItems: ItemIpad[];

@OneToMany(() => ItemIphone, (iphoneItem) => iphoneItem.modelEntity)
@JoinColumn([
{ name: 'type', referencedColumnName: 'type' },
{ name: 'id', referencedColumnName: 'model' },
])
iphoneItems: ItemIphone[];
}
12 changes: 11 additions & 1 deletion src/lib/alert/payload.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AlertTarget, Deal, Item, PriceTrade } from '../../entities';

const generateSpec = (item: Item): { main: string; detail: string } => {
const { macbook, ipad } = item;
const { macbook, ipad, iphone } = item;

if (macbook) {
const { modelEntity, chip, cpu, gpu, ram, ssd } = macbook;
Expand All @@ -23,6 +23,16 @@ const generateSpec = (item: Item): { main: string; detail: string } => {
};
}

if (iphone) {
const { modelEntity, modelSuffix, phoneStorage } = iphone;
const { name } = modelEntity;

return {
main: `${name} ${modelSuffix}`,
detail: `${phoneStorage}`,
};
}

return { main: '', detail: '' };
};

Expand Down
13 changes: 13 additions & 0 deletions src/lib/relations/item.detail.relation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { FindOptionsRelations } from 'typeorm';
import { Item } from '../../entities';
import { ItemDetailEntity } from '../../entities/item/detall.entity';

const getItemDetailRelation = (
inner: FindOptionsRelations<ItemDetailEntity>,
): FindOptionsRelations<Item> => ({
macbook: { ...inner },
ipad: { ...inner },
iphone: { ...inner },
});

export { getItemDetailRelation };
3 changes: 2 additions & 1 deletion src/services/deal.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
Repository,
} from 'typeorm';
import { Deal } from '../entities';
import { getItemDetailRelation } from '../lib/relations/item.detail.relation';

export class DealService {
private dealRepository: Repository<Deal>;
Expand All @@ -17,7 +18,7 @@ export class DealService {
async getTargetDeals() {
const where: FindOptionsWhere<Deal> = { alertedAt: IsNull() };
const relations: FindOptionsRelations<Deal> = {
item: { macbook: { modelEntity: {} }, ipad: { modelEntity: {} } },
item: getItemDetailRelation({ modelEntity: {} }),
};
return this.dealRepository.find({ where, relations });
}
Expand Down

0 comments on commit 23bb673

Please sign in to comment.