Sorting categories body in the observable (#6041)

* Sorting categories body in the observable

* feedback review

* Fix category queries to return only channels that have been loaded

* Do not display archived channels unless is the active one

Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
This commit is contained in:
Shaz MJ
2022-03-11 08:19:49 +11:00
committed by GitHub
parent 5b44676985
commit 23ff6e8a09
9 changed files with 155 additions and 85 deletions

View File

@@ -67,18 +67,20 @@ export default class CategoryModel extends Model implements CategoryInterface {
@children(CATEGORY_CHANNEL) categoryChannels!: Query<CategoryChannelModel>;
/** categoryChannelsBySortOrder : Retrieves assocated category channels sorted by sort_order */
@lazy categoryChannelsBySortOrder = this.categoryChannels.collection.query(
Q.where('category_id', this.id),
Q.sortBy('sort_order', Q.asc),
);
@lazy categoryChannelsBySortOrder = this.categoryChannels.collection.
query(
Q.on(MY_CHANNEL,
Q.where('id', Q.notEq('')),
),
Q.where('category_id', this.id),
Q.sortBy('sort_order', Q.asc),
);
/** channels : Retrieves all the channels that are part of this category */
@lazy channels = this.collections.
get<ChannelModel>(CHANNEL).
query(
Q.on(CATEGORY_CHANNEL, 'category_id', this.id),
Q.where('delete_at', Q.eq(0)),
Q.sortBy('display_name'),
);
/** myChannels : Retrieves all myChannels that are part of this category */
@@ -88,7 +90,7 @@ export default class CategoryModel extends Model implements CategoryInterface {
Q.experimentalJoinTables([CHANNEL, CATEGORY_CHANNEL]),
Q.on(CATEGORY_CHANNEL,
Q.and(
Q.on(CHANNEL, Q.where('delete_at', Q.eq(0))),
Q.on(CHANNEL, Q.where('create_at', Q.gte(0))),
Q.where('category_id', this.id),
),
),