Skip to content

Commit

Permalink
chore(api-service,dashboard): Replace create_at sorting with _id for …
Browse files Browse the repository at this point in the history
…subscribers
  • Loading branch information
desiprisg committed Jan 29, 2025
1 parent 94ef255 commit b600c92
Show file tree
Hide file tree
Showing 10 changed files with 193 additions and 227 deletions.
364 changes: 170 additions & 194 deletions apps/api/src/app/subscribers-v2/subscriber.controller.e2e.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion apps/api/src/app/subscribers-v2/subscriber.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class SubscriberController {
after: query.after,
before: query.before,
orderDirection: query.orderDirection || DirectionEnum.DESC,
orderBy: query.orderBy || 'createdAt',
orderBy: query.orderBy || '_id',
email: query.email,
phone: query.phone,
subscriberId: query.subscriberId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export class ListSubscribersCommand extends CursorBasedPaginatedCommand {
@IsOptional()
orderDirection: DirectionEnum = DirectionEnum.DESC;

@IsEnum(['updatedAt', 'createdAt'])
@IsEnum(['updatedAt', '_id'])
@IsOptional()
orderBy: 'updatedAt' | 'createdAt' = 'createdAt';
orderBy: 'updatedAt' | '_id' = '_id';

@IsString()
@IsOptional()
Expand Down
4 changes: 2 additions & 2 deletions apps/dashboard/src/components/subscribers/subscriber-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ const SubscriberListTable = (props: SubscriberListTableProps) => {
<TableHead>Phone number</TableHead>
<TableHead
sortable
sortDirection={orderBy === 'createdAt' ? orderDirection : false}
onSort={() => toggleSort('createdAt')}
sortDirection={orderBy === '_id' ? orderDirection : false}
onSort={() => toggleSort('_id')}
>
Created at
</TableHead>
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/src/hooks/use-fetch-subscribers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function useFetchSubscribers(
email = '',
phone = '',
orderDirection = DirectionEnum.DESC,
orderBy = 'createdAt',
orderBy = '_id',
name = '',
subscriberId = '',
limit = 10,
Expand Down
10 changes: 5 additions & 5 deletions apps/dashboard/src/hooks/use-subscribers-url-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useCallback, useMemo } from 'react';
import { useNavigate, useSearchParams } from 'react-router-dom';
import { useDebounce } from '../hooks/use-debounce';

export type SubscribersSortableColumn = 'createdAt' | 'updatedAt';
export type SubscribersSortableColumn = '_id' | 'updatedAt';
export interface SubscribersFilter {
email?: string;
phone?: string;
Expand All @@ -16,15 +16,15 @@ export interface SubscribersFilter {
orderDirection?: DirectionEnum;
}

export const defaultSubscribersFilter: SubscribersFilter = {
export const defaultSubscribersFilter: Required<SubscribersFilter> = {
email: '',
phone: '',
name: '',
subscriberId: '',
limit: 10,
after: '',
before: '',
orderBy: 'createdAt',
orderBy: '_id',
orderDirection: DirectionEnum.DESC,
};

Expand Down Expand Up @@ -54,10 +54,10 @@ export function useSubscribersUrlState(props: UseSubscribersUrlStateProps): Subs
phone: searchParams.get('phone') || '',
name: searchParams.get('name') || '',
subscriberId: searchParams.get('subscriberId') || '',
limit: parseInt(searchParams.get('limit') || '10', 10),
limit: parseInt(searchParams.get('limit') || defaultSubscribersFilter.limit.toString(), 10),
after: searchParams.get('after') || '',
before: searchParams.get('before') || '',
orderBy: (searchParams.get('orderBy') as SubscribersSortableColumn) || 'createdAt',
orderBy: (searchParams.get('orderBy') as SubscribersSortableColumn) || defaultSubscribersFilter.orderBy,
orderDirection: (searchParams.get('orderDirection') as DirectionEnum) || DirectionEnum.DESC,
}),
[searchParams]
Expand Down
8 changes: 6 additions & 2 deletions libs/dal/src/repositories/subscriber/subscriber.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export class SubscriberRepository extends BaseRepository<SubscriberDBModel, Subs
environmentId: string;
organizationId: string;
limit: number;
sortBy: 'updatedAt' | 'createdAt';
sortBy: 'updatedAt' | '_id';
sortDirection: DirectionEnum;
after?: string;
before?: string;
Expand All @@ -187,7 +187,11 @@ export class SubscriberRepository extends BaseRepository<SubscriberDBModel, Subs
_id: id,
});
if (!subscriber) {
throw new DalException('Subscriber not found');
return {
subscribers: [],
next: null,
previous: null,
};
}
}

Expand Down
17 changes: 1 addition & 16 deletions libs/dal/src/repositories/subscriber/subscriber.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,20 +193,6 @@ subscriberSchema.index({
deleted: 1,
});

subscriberSchema.index({
_environmentId: 1,
_organizationId: 1,
createdAt: 1,
_id: 1,
});

subscriberSchema.index({
_environmentId: 1,
_organizationId: 1,
createdAt: -1,
_id: -1,
});

subscriberSchema.index({
_environmentId: 1,
_organizationId: 1,
Expand All @@ -217,8 +203,7 @@ subscriberSchema.index({
subscriberSchema.index({
_environmentId: 1,
_organizationId: 1,
updatedAt: -1,
_id: -1,
_id: 1,
});

subscriberSchema.plugin(mongooseDelete, { deletedAt: true, deletedBy: true, overrideMethods: 'all' });
Expand Down
7 changes: 4 additions & 3 deletions libs/testing/src/user.session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { ClerkJwtPayload } from './ee/types';
type UserSessionOptions = {
noOrganization?: boolean;
noEnvironment?: boolean;
noWidgetSession?: boolean;
showOnBoardingTour?: boolean;
ee?: {
userId: 'clerk_user_1' | 'clerk_user_2';
Expand Down Expand Up @@ -125,7 +126,7 @@ export class UserSession {
await this.addOrganizationCommunity();
}

if (!options.noOrganization && !options?.noEnvironment) {
if (!options.noOrganization && !options?.noEnvironment && !options.noWidgetSession) {
await this.createEnvironmentsAndFeeds();
}

Expand All @@ -137,7 +138,7 @@ export class UserSession {
}
}

if (!options.noOrganization && !options.noEnvironment) {
if (!options.noOrganization && !options.noEnvironment && !options.noWidgetSession) {
const { token, profile } = await this.initializeWidgetSession();
this.subscriberToken = token;
this.subscriberProfile = profile;
Expand Down Expand Up @@ -179,7 +180,7 @@ export class UserSession {
}
}

if (!options.noOrganization && !options.noEnvironment) {
if (!options.noOrganization && !options.noEnvironment && !options.noWidgetSession) {
const { token, profile } = await this.initializeWidgetSession();
this.subscriberToken = token;
this.subscriberProfile = profile;
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/src/dto/subscriber/list-subscribers.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface IListSubscribersRequestDto {

orderDirection: DirectionEnum;

orderBy: 'updatedAt' | 'createdAt';
orderBy: 'updatedAt' | '_id';

email?: string;

Expand Down

0 comments on commit b600c92

Please sign in to comment.