mirror of
https://github.com/hexastack/hexabot
synced 2025-01-22 18:45:57 +00:00
feat: implement dynamic create DTO for Subscriber
This commit is contained in:
parent
dc7d451378
commit
7578c485f1
@ -161,7 +161,6 @@ export class ChannelService {
|
|||||||
foreign_id: req.session.passport.user.id,
|
foreign_id: req.session.passport.user.id,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: req.session.passport.user.id,
|
|
||||||
foreign_id: req.session.passport.user.id,
|
foreign_id: req.session.passport.user.id,
|
||||||
first_name: req.session.passport.user.first_name,
|
first_name: req.session.passport.user.first_name,
|
||||||
last_name: req.session.passport.user.last_name,
|
last_name: req.session.passport.user.last_name,
|
||||||
|
@ -17,6 +17,7 @@ import {
|
|||||||
} from 'class-validator';
|
} from 'class-validator';
|
||||||
|
|
||||||
import { ChannelName } from '@/channel/types';
|
import { ChannelName } from '@/channel/types';
|
||||||
|
import { DtoConfig } from '@/utils/types/dto.types';
|
||||||
import { IsObjectId } from '@/utils/validation-rules/is-object-id';
|
import { IsObjectId } from '@/utils/validation-rules/is-object-id';
|
||||||
|
|
||||||
import { SubscriberChannelData } from '../schemas/types/channel';
|
import { SubscriberChannelData } from '../schemas/types/channel';
|
||||||
@ -36,7 +37,7 @@ export class SubscriberCreateDto {
|
|||||||
@ApiPropertyOptional({ description: 'Subscriber locale', type: String })
|
@ApiPropertyOptional({ description: 'Subscriber locale', type: String })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
locale: string;
|
locale?: string;
|
||||||
|
|
||||||
@ApiPropertyOptional({ description: 'Subscriber timezone', type: Number })
|
@ApiPropertyOptional({ description: 'Subscriber timezone', type: Number })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@ -51,17 +52,17 @@ export class SubscriberCreateDto {
|
|||||||
@ApiPropertyOptional({ description: 'Subscriber gender', type: String })
|
@ApiPropertyOptional({ description: 'Subscriber gender', type: String })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
gender: string;
|
gender?: string;
|
||||||
|
|
||||||
@ApiPropertyOptional({ description: 'Subscriber country', type: String })
|
@ApiPropertyOptional({ description: 'Subscriber country', type: String })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
country: string;
|
country?: string;
|
||||||
|
|
||||||
@ApiPropertyOptional({ description: 'Subscriber foreign id', type: String })
|
@ApiPropertyOptional({ description: 'Subscriber foreign id', type: String })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsString()
|
@IsString()
|
||||||
foreign_id: string;
|
foreign_id?: string;
|
||||||
|
|
||||||
@ApiProperty({ description: 'Subscriber labels', type: Array })
|
@ApiProperty({ description: 'Subscriber labels', type: Array })
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
@ -114,3 +115,7 @@ export class SubscriberCreateDto {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class SubscriberUpdateDto extends PartialType(SubscriberCreateDto) {}
|
export class SubscriberUpdateDto extends PartialType(SubscriberCreateDto) {}
|
||||||
|
|
||||||
|
export type UserDtoMapActions = DtoConfig<{
|
||||||
|
create: SubscriberCreateDto;
|
||||||
|
}>;
|
||||||
|
@ -20,7 +20,7 @@ import {
|
|||||||
import { BaseRepository } from '@/utils/generics/base-repository';
|
import { BaseRepository } from '@/utils/generics/base-repository';
|
||||||
import { TFilterQuery } from '@/utils/types/filter.types';
|
import { TFilterQuery } from '@/utils/types/filter.types';
|
||||||
|
|
||||||
import { SubscriberUpdateDto } from '../dto/subscriber.dto';
|
import { SubscriberUpdateDto, UserDtoMapActions } from '../dto/subscriber.dto';
|
||||||
import {
|
import {
|
||||||
Subscriber,
|
Subscriber,
|
||||||
SUBSCRIBER_POPULATE,
|
SUBSCRIBER_POPULATE,
|
||||||
@ -33,7 +33,8 @@ import {
|
|||||||
export class SubscriberRepository extends BaseRepository<
|
export class SubscriberRepository extends BaseRepository<
|
||||||
Subscriber,
|
Subscriber,
|
||||||
SubscriberPopulate,
|
SubscriberPopulate,
|
||||||
SubscriberFull
|
SubscriberFull,
|
||||||
|
UserDtoMapActions
|
||||||
> {
|
> {
|
||||||
constructor(
|
constructor(
|
||||||
readonly eventEmitter: EventEmitter2,
|
readonly eventEmitter: EventEmitter2,
|
||||||
|
@ -28,7 +28,7 @@ import { SocketRequest } from '@/websocket/utils/socket-request';
|
|||||||
import { SocketResponse } from '@/websocket/utils/socket-response';
|
import { SocketResponse } from '@/websocket/utils/socket-response';
|
||||||
import { WebsocketGateway } from '@/websocket/websocket.gateway';
|
import { WebsocketGateway } from '@/websocket/websocket.gateway';
|
||||||
|
|
||||||
import { SubscriberUpdateDto } from '../dto/subscriber.dto';
|
import { SubscriberUpdateDto, UserDtoMapActions } from '../dto/subscriber.dto';
|
||||||
import { SubscriberRepository } from '../repositories/subscriber.repository';
|
import { SubscriberRepository } from '../repositories/subscriber.repository';
|
||||||
import {
|
import {
|
||||||
Subscriber,
|
Subscriber,
|
||||||
@ -40,7 +40,8 @@ import {
|
|||||||
export class SubscriberService extends BaseService<
|
export class SubscriberService extends BaseService<
|
||||||
Subscriber,
|
Subscriber,
|
||||||
SubscriberPopulate,
|
SubscriberPopulate,
|
||||||
SubscriberFull
|
SubscriberFull,
|
||||||
|
UserDtoMapActions
|
||||||
> {
|
> {
|
||||||
private readonly gateway: WebsocketGateway;
|
private readonly gateway: WebsocketGateway;
|
||||||
|
|
||||||
|
23
api/src/utils/test/fixtures/subscriber.ts
vendored
23
api/src/utils/test/fixtures/subscriber.ts
vendored
@ -8,8 +8,8 @@
|
|||||||
|
|
||||||
import mongoose from 'mongoose';
|
import mongoose from 'mongoose';
|
||||||
|
|
||||||
import { SubscriberCreateDto } from '@/chat/dto/subscriber.dto';
|
|
||||||
import { Subscriber, SubscriberModel } from '@/chat/schemas/subscriber.schema';
|
import { Subscriber, SubscriberModel } from '@/chat/schemas/subscriber.schema';
|
||||||
|
import { BaseSchema } from '@/utils/generics/base-schema';
|
||||||
|
|
||||||
import { getFixturesWithDefaultValues } from '../defaultValues';
|
import { getFixturesWithDefaultValues } from '../defaultValues';
|
||||||
import { TFixturesDefaultValues } from '../types';
|
import { TFixturesDefaultValues } from '../types';
|
||||||
@ -17,7 +17,22 @@ import { TFixturesDefaultValues } from '../types';
|
|||||||
import { installLabelFixtures } from './label';
|
import { installLabelFixtures } from './label';
|
||||||
import { installUserFixtures } from './user';
|
import { installUserFixtures } from './user';
|
||||||
|
|
||||||
const subscribers: SubscriberCreateDto[] = [
|
export const fieldsWithDefaultValues = {
|
||||||
|
context: {},
|
||||||
|
avatar: null,
|
||||||
|
assignedAt: null,
|
||||||
|
assignedTo: null,
|
||||||
|
timezone: 0,
|
||||||
|
} satisfies Partial<Subscriber>;
|
||||||
|
|
||||||
|
type TFieldWithDefaultValues =
|
||||||
|
| keyof typeof fieldsWithDefaultValues
|
||||||
|
| keyof BaseSchema;
|
||||||
|
type TTransformedField<T> = Omit<T, TFieldWithDefaultValues> &
|
||||||
|
Partial<Pick<Subscriber, TFieldWithDefaultValues>>;
|
||||||
|
type TSubscriber = TTransformedField<Subscriber>;
|
||||||
|
|
||||||
|
const subscribers: TSubscriber[] = [
|
||||||
{
|
{
|
||||||
foreign_id: 'foreign-id-messenger',
|
foreign_id: 'foreign-id-messenger',
|
||||||
first_name: 'Jhon',
|
first_name: 'Jhon',
|
||||||
@ -30,7 +45,6 @@ const subscribers: SubscriberCreateDto[] = [
|
|||||||
name: 'messenger-channel',
|
name: 'messenger-channel',
|
||||||
},
|
},
|
||||||
labels: [],
|
labels: [],
|
||||||
assignedAt: null,
|
|
||||||
lastvisit: new Date('2020-01-01T20:40:03.249Z'),
|
lastvisit: new Date('2020-01-01T20:40:03.249Z'),
|
||||||
retainedFrom: new Date('2020-01-01T20:40:03.249Z'),
|
retainedFrom: new Date('2020-01-01T20:40:03.249Z'),
|
||||||
},
|
},
|
||||||
@ -46,7 +60,6 @@ const subscribers: SubscriberCreateDto[] = [
|
|||||||
name: 'web-channel',
|
name: 'web-channel',
|
||||||
},
|
},
|
||||||
labels: [],
|
labels: [],
|
||||||
assignedAt: null,
|
|
||||||
lastvisit: new Date('2021-01-01T20:40:03.249Z'),
|
lastvisit: new Date('2021-01-01T20:40:03.249Z'),
|
||||||
retainedFrom: new Date('2021-01-02T20:40:03.249Z'),
|
retainedFrom: new Date('2021-01-02T20:40:03.249Z'),
|
||||||
},
|
},
|
||||||
@ -62,7 +75,6 @@ const subscribers: SubscriberCreateDto[] = [
|
|||||||
name: 'web-channel',
|
name: 'web-channel',
|
||||||
},
|
},
|
||||||
labels: [],
|
labels: [],
|
||||||
assignedAt: null,
|
|
||||||
lastvisit: new Date('2022-01-01T20:40:03.249Z'),
|
lastvisit: new Date('2022-01-01T20:40:03.249Z'),
|
||||||
retainedFrom: new Date('2022-01-02T20:40:03.249Z'),
|
retainedFrom: new Date('2022-01-02T20:40:03.249Z'),
|
||||||
},
|
},
|
||||||
@ -78,7 +90,6 @@ const subscribers: SubscriberCreateDto[] = [
|
|||||||
name: 'web-channel',
|
name: 'web-channel',
|
||||||
},
|
},
|
||||||
labels: [],
|
labels: [],
|
||||||
assignedAt: null,
|
|
||||||
lastvisit: new Date('2024-01-01T20:40:03.249Z'),
|
lastvisit: new Date('2024-01-01T20:40:03.249Z'),
|
||||||
retainedFrom: new Date('2024-01-02T20:40:03.249Z'),
|
retainedFrom: new Date('2024-01-02T20:40:03.249Z'),
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user