Skip to content

Commit

Permalink
feat(RL-133): adds categorizable model
Browse files Browse the repository at this point in the history
  • Loading branch information
NoodleOfDeath committed Oct 23, 2023
1 parent 17cf8bf commit 9d14ca1
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/server/src/api/v1/schema/associations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
ServiceStatus,
Subscription,
Summary,
SummaryCategory,
SummaryInteraction,
SummaryMedia,
SummaryRelation,
Expand Down Expand Up @@ -110,7 +111,14 @@ export function makeAssociations() {
Summary.belongsTo(Publisher, { foreignKey: 'publisherId' });
Publisher.hasMany(Summary, { foreignKey: 'publisherId' });

Summary.belongsTo(Category, { foreignKey: 'categoryId' });
Summary.belongsToMany(Category, {
foreignKey: 'parentId',
through: SummaryCategory,
});
SummaryCategory.hasMany(Summary, {
foreignKey: 'categoryId',
sourceKey: 'parentId',
});
Category.hasMany(Summary, { foreignKey: 'categoryId' });

SentimentMethod.hasMany(SummarySentiment, { foreignKey: 'method', sourceKey: 'name' });
Expand Down
1 change: 1 addition & 0 deletions src/server/src/api/v1/schema/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export * from './resources/channel/Category.model';
export * from './resources/channel/CategoryTranslation.model';

export * from './resources/summary/Summary.model';
export * from './resources/summary/SummaryCategory.model';
export * from './resources/summary/SummarySentiment.model';
export * from './resources/summary/SummaryInteraction.model';
export * from './resources/summary/SummaryTranslation.model';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Column, DataType } from 'sequelize-typescript';

import { CategorizableAttributes, CategorizableCreationAttributes } from './Categorizable.types';
import { BaseModel } from '../../base';

export class Categorizable<
A extends CategorizableAttributes = CategorizableAttributes,
B extends CategorizableCreationAttributes = CategorizableCreationAttributes>
extends BaseModel<A, B>
implements CategorizableAttributes {

@Column({
allowNull: false,
type: DataType.INTEGER,
})
declare parentId: number;

@Column({
allowNull: false,
type: DataType.STRING,
})
declare category: string;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { DatedAttributes } from '../../types';

export type CategorizableAttributes = DatedAttributes & {
parentId: number;
category: string;
};

export type CategorizableCreationAttributes = Partial<DatedAttributes> & {
parentId: number;
category: string;
};

export const PUBLIC_CATEGORIZABLE_ATTRIBUTES = ['parentId', 'category'] as const;

export type PublicCategorizableAttributes = Pick<CategorizableAttributes, typeof PUBLIC_CATEGORIZABLE_ATTRIBUTES[number]>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Table } from 'sequelize-typescript';

import {
SummaryCategoryAttributes,
SummaryCategoryCreationAttributes,
} from './SummaryCategory.types';
import { Categorizable } from '../channel/Categorizable.model';

@Table({
modelName: 'summary_category',
paranoid: true,
timestamps: true,
})
export class SummaryCategory<A extends SummaryCategoryAttributes = SummaryCategoryAttributes, B extends SummaryCategoryCreationAttributes = SummaryCategoryCreationAttributes> extends Categorizable<A, B> implements SummaryCategoryAttributes {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {
CategorizableAttributes,
CategorizableCreationAttributes,
PUBLIC_CATEGORIZABLE_ATTRIBUTES,
PublicCategorizableAttributes,
} from '../channel/Categorizable.types';

export type SummaryCategoryAttributes = CategorizableAttributes;
export type SummaryCategoryCreationAttributes = CategorizableCreationAttributes;

export const PUBLIC_SUMMARY_CATEGORIZABLE_ATTRIBUTES = PUBLIC_CATEGORIZABLE_ATTRIBUTES;

export type PublicSummaryCategoryAttributes = PublicCategorizableAttributes;
1 change: 1 addition & 0 deletions src/server/src/api/v1/schema/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export * from './resources/channel/Category.types';
export * from './resources/channel/CategoryTranslation.types';

export * from './resources/summary/Summary.types';
export * from './resources/summary/SummaryCategory.types';
export * from './resources/summary/SummarySentiment.types';
export * from './resources/summary/SummaryInteraction.types';
export * from './resources/summary/SummaryTranslation.types';
Expand Down
2 changes: 1 addition & 1 deletion src/server/src/services/scribe/ScribeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ export class ScribeService extends BaseService {
}

try {
await Summary.refreshViews();
await Summary.refreshViews(['refresh_summary_media_view', 'refresh_summary_sentiment_view']);
} catch (e) {
console.error(e);
}
Expand Down

0 comments on commit 9d14ca1

Please sign in to comment.