-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add the create get and patch action for influencer resource
- Loading branch information
1 parent
9ebfbbe
commit 83a13a9
Showing
27 changed files
with
542 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,5 @@ | |
"tabWidth": 4, | ||
"semi": true, | ||
"singleQuote": true, | ||
"printWidth": 100 | ||
"printWidth": 120 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,23 @@ | ||
import mockedInfluences from './influencers.mock.json'; | ||
|
||
import { envVars } from '../../utils'; | ||
import { InfluencerModel } from '../../routes/influencer/index.model'; | ||
import { InfluencerRequest } from '../../routes/influencer/index.types'; | ||
|
||
export class Seeder { | ||
public static async run() { | ||
await Seeder.seedInfluencers(); | ||
} | ||
|
||
private static async seedInfluencers() {} | ||
private static async seedInfluencers() { | ||
if (envVars.NODE_ENV != 'development') return; | ||
|
||
const influencersResponse = await InfluencerModel.all(); | ||
|
||
if (!influencersResponse.length) { | ||
for (const influencer of mockedInfluences) { | ||
await InfluencerModel.create(influencer as InfluencerRequest); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,86 @@ | ||
[] | ||
[ | ||
{ | ||
"firstName": "Alice", | ||
"lastName": "Smith", | ||
"socialMediaHandles": [ | ||
{ | ||
"type": "instagram", | ||
"userName": "alice_smith" | ||
}, | ||
{ | ||
"type": "tiktok", | ||
"userName": "alice_tiktok" | ||
} | ||
], | ||
"manager": { | ||
"id": "m1", | ||
"imgUrl": "https://example.com/images/m1.jpg", | ||
"firstName": "Bob", | ||
"lastName": "Johnson", | ||
"email": "[email protected]" | ||
} | ||
}, | ||
{ | ||
"firstName": "John", | ||
"lastName": "Doe", | ||
"socialMediaHandles": [ | ||
{ | ||
"type": "instagram", | ||
"userName": "john_doe" | ||
}, | ||
{ | ||
"type": "tiktok", | ||
"userName": "john_doe_tiktok" | ||
} | ||
], | ||
"manager": { | ||
"id": "m2", | ||
"imgUrl": null, | ||
"firstName": "Sarah", | ||
"lastName": "Connor", | ||
"email": null | ||
} | ||
}, | ||
{ | ||
"firstName": "Emily", | ||
"lastName": "Davis", | ||
"socialMediaHandles": [ | ||
{ | ||
"type": "instagram", | ||
"userName": "emily_davis" | ||
}, | ||
{ | ||
"type": "tiktok", | ||
"userName": "emily_tiktok" | ||
} | ||
], | ||
"manager": { | ||
"id": "m3", | ||
"imgUrl": "https://example.com/images/m3.jpg", | ||
"firstName": "Michael", | ||
"lastName": "Smith", | ||
"email": "[email protected]" | ||
} | ||
}, | ||
{ | ||
"firstName": "Chris", | ||
"lastName": "Brown", | ||
"socialMediaHandles": [ | ||
{ | ||
"type": "instagram", | ||
"userName": "chris_brown" | ||
}, | ||
{ | ||
"type": "tiktok", | ||
"userName": "chris_brown_tiktok" | ||
} | ||
], | ||
"manager": { | ||
"id": "m4", | ||
"imgUrl": null, | ||
"firstName": "Jessica", | ||
"lastName": "Taylor", | ||
"email": null | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './mongo-id-normalize.plugin'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,73 @@ | ||
export {}; | ||
/* eslint-disable no-unused-vars */ | ||
|
||
import { | ||
IsString, | ||
IsNotEmpty, | ||
IsArray, | ||
ValidateNested, | ||
IsOptional, | ||
IsEmail, | ||
MaxLength, | ||
IsEnum, | ||
} from 'class-validator'; | ||
import { Type } from 'class-transformer'; | ||
|
||
export enum SocialMediaType { | ||
Instagram = 'instagram', | ||
TikTok = 'tiktok', | ||
} | ||
|
||
class SocialMediaHandleDto { | ||
@IsEnum(SocialMediaType, { message: 'Social media handle must be either instagram or tiktok' }) | ||
@IsNotEmpty({ message: 'Social media handle type is required' }) | ||
type: SocialMediaType; | ||
|
||
@IsString() | ||
@IsNotEmpty({ message: 'Social media handle username is required' }) | ||
userName: string; | ||
} | ||
|
||
class ManagerDto { | ||
@IsString() | ||
@IsNotEmpty({ message: 'Manager ID is required' }) | ||
id: string; | ||
|
||
@IsOptional() | ||
@IsString() | ||
imgUrl?: string; | ||
|
||
@IsString() | ||
@IsNotEmpty({ message: 'Manager first name is required' }) | ||
@MaxLength(50, { message: 'Manager first name cannot exceed 50 characters' }) | ||
firstName: string; | ||
|
||
@IsString() | ||
@IsNotEmpty({ message: 'Manager last name is required' }) | ||
@MaxLength(50, { message: 'Manager last name cannot exceed 50 characters' }) | ||
lastName: string; | ||
|
||
@IsOptional() | ||
@IsEmail({}, { message: 'Invalid email format' }) | ||
email?: string; | ||
} | ||
|
||
export class CreateInfluencerDto { | ||
@IsString() | ||
@IsNotEmpty({ message: 'First name is required' }) | ||
@MaxLength(50, { message: 'First name cannot exceed 50 characters' }) | ||
firstName: string; | ||
|
||
@IsString() | ||
@IsNotEmpty({ message: 'Last name is required' }) | ||
@MaxLength(50, { message: 'Last name cannot exceed 50 characters' }) | ||
lastName: string; | ||
|
||
@IsArray() | ||
@ValidateNested({ each: true }) | ||
@Type(() => SocialMediaHandleDto) | ||
socialMediaHandles: SocialMediaHandleDto[]; | ||
|
||
@ValidateNested() | ||
@Type(() => ManagerDto) | ||
manager: ManagerDto; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,49 @@ | ||
export {}; | ||
import { Type } from 'class-transformer'; | ||
import { IsOptional, ValidateNested, IsString, IsNotEmpty, MaxLength } from 'class-validator'; | ||
|
||
class ManagerDto { | ||
@IsString() | ||
@IsNotEmpty({ message: 'Manager ID is required' }) | ||
id: string; | ||
|
||
@IsOptional() | ||
@IsString() | ||
imgUrl?: string; | ||
|
||
@IsString() | ||
@IsNotEmpty({ message: 'Manager first name is required' }) | ||
@MaxLength(50, { message: 'Manager first name cannot exceed 50 characters' }) | ||
firstName: string; | ||
|
||
@IsString() | ||
@IsNotEmpty({ message: 'Manager last name is required' }) | ||
@MaxLength(50, { message: 'Manager last name cannot exceed 50 characters' }) | ||
lastName: string; | ||
|
||
@IsOptional() | ||
@IsString() | ||
email?: string; | ||
} | ||
|
||
export class PatchInfluencerDto { | ||
@ValidateNested() | ||
@Type(() => ManagerDto) | ||
manager: ManagerDto; | ||
|
||
@IsOptional() | ||
@IsString() | ||
@MaxLength(50, { message: 'First name cannot exceed 50 characters' }) | ||
firstName?: string; | ||
|
||
@IsOptional() | ||
@IsString() | ||
@MaxLength(50, { message: 'Last name cannot exceed 50 characters' }) | ||
lastName?: string; | ||
|
||
@IsOptional() | ||
@ValidateNested({ each: true }) | ||
socialMediaHandles?: Array<{ | ||
type: 'instagram' | 'tiktok'; | ||
userName: string; | ||
}>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,10 @@ | ||
export {}; | ||
import { asyncHandler } from '../../middlewares'; | ||
import { InfluencerServices } from './index.services'; | ||
|
||
export class InfluencerController { | ||
public static httpCreateInfluencer = asyncHandler(InfluencerServices.createInfluencer); | ||
|
||
public static httpGetInfluencers = asyncHandler(InfluencerServices.getInfluencers); | ||
|
||
public static httpPatchInfluencer = asyncHandler(InfluencerServices.patchInfluencer); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,24 @@ | ||
export {}; | ||
import { Influencer } from './index.schema'; | ||
import { InfluencerRequest, InfluencerQueryParams } from './index.types'; | ||
|
||
export class InfluencerModel { | ||
public static create(influencer: InfluencerRequest) { | ||
return Influencer.create(influencer); | ||
} | ||
|
||
public static all() { | ||
return Influencer.find().lean().exec(); | ||
} | ||
|
||
public static getByNameOrManager({ firstName, lastName, managerId }: InfluencerQueryParams) { | ||
const query: any = {}; | ||
if (firstName) query.firstName = firstName; | ||
if (lastName) query.lastName = lastName; | ||
if (managerId) query['manager.id'] = managerId; | ||
return Influencer.find(query).lean().exec(); | ||
} | ||
|
||
public static update(id: string, influencer: Partial<InfluencerRequest>) { | ||
return Influencer.findByIdAndUpdate(id, influencer, { new: true, runValidators: true }).lean().exec(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
import { Router } from 'express'; | ||
|
||
import { InfluencerController } from './index.controller'; | ||
|
||
const influencerRouter = Router(); | ||
|
||
influencerRouter.post('/', InfluencerController.httpCreateInfluencer); | ||
influencerRouter.get('/', InfluencerController.httpGetInfluencers); | ||
influencerRouter.patch('/:id', InfluencerController.httpPatchInfluencer); | ||
|
||
export { influencerRouter }; |
Oops, something went wrong.