Skip to content

Commit

Permalink
feat: user create artist api
Browse files Browse the repository at this point in the history
  • Loading branch information
harisato committed Oct 16, 2024
1 parent 6b17dd7 commit e785076
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 147 deletions.
6 changes: 0 additions & 6 deletions hasura/metadata/actions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ actions:
email: '{{$body.input.email}}'
template_engine: Kriti
version: 2
response_transform:
body:
action: transform
template: "{{ if $response.status == 200 }}\r\n {\r\n \"error\": {{$body.error}},\r\n \"message\": {{$body.message}}\r\n }\r\n{{ elif $response.status == 400 }}\r\n { \r\n \"message\": {{$body.error}}\r\n }\r\n{{ elif $response.status == 500 }}\r\n { \r\n \"message\": {{$response}}\r\n }\r\n{{ else }}\r\n { \r\n \"message\" : \"internal error\"\r\n }\r\n{{ end }}"
template_engine: Kriti
version: 2
comment: delete user
custom_types:
enums: []
Expand Down
12 changes: 1 addition & 11 deletions hasura/metadata/backend_configs.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1 @@
dataconnector:
athena:
uri: http://data-connector-agent:8081/api/v1/athena
mariadb:
uri: http://data-connector-agent:8081/api/v1/mariadb
mysql8:
uri: http://data-connector-agent:8081/api/v1/mysql
oracle:
uri: http://data-connector-agent:8081/api/v1/oracle
snowflake:
uri: http://data-connector-agent:8081/api/v1/snowflake
{}
199 changes: 70 additions & 129 deletions hasura/metadata/query_collections.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1038,70 +1038,6 @@
}
}
}
- name: User - Get Profile
query: |
query GetUserProfile {
authorizer_users(limit: 1) {
id
email
email_verified_at
bio
birthdate
gender
active_wallet_address: active_evm_address
wallet_address
nickname
picture
signup_methods
levels {
xp
level
user_level_chain {
id
name
punkga_config
}
}
authorizer_users_user_wallet {
address
}
user_quests_aggregate {
aggregate {
count
}
}
user_quests(order_by: {created_at:desc}, limit: 20) {
created_at
status
user_quest_rewards {
tx_hash
}
quest {
id
name
quests_campaign {
campaign_chain {
punkga_config
}
}
quests_i18n {
id
quest_id
language_id
data
i18n_language {
id
description
icon
is_main
symbol
}
}
reward
}
}
}
}
- name: Public - Get manga by creator
query: |
query manga ($id: Int!, $limit: Int = 10, $offset: Int = 0) {
Expand Down Expand Up @@ -1435,71 +1371,6 @@
}
}
}
- name: User - Get Profile
query: |
query GetUserProfile {
authorizer_users(limit: 1) {
id
email
email_verified_at
bio
birthdate
gender
active_wallet_address: active_evm_address
wallet_address
ton_wallet_address
nickname
picture
signup_methods
levels {
xp
level
user_level_chain {
id
name
punkga_config
}
}
authorizer_users_user_wallet {
address
}
user_quests_aggregate {
aggregate {
count
}
}
user_quests(order_by: {created_at:desc}, limit: 20) {
created_at
status
user_quest_rewards {
tx_hash
}
quest {
id
name
quests_campaign {
campaign_chain {
punkga_config
}
}
quests_i18n {
id
quest_id
language_id
data
i18n_language {
id
description
icon
is_main
symbol
}
}
reward
}
}
}
}
- name: Admin - Query List Manga
query: |
query QueryListManga {
Expand Down Expand Up @@ -1666,3 +1537,73 @@
created_at
}
}
- name: User - Get Profile
query: |
query GetUserProfile {
authorizer_users(limit: 1) {
id
email
email_verified_at
bio
birthdate
gender
active_wallet_address: active_evm_address
wallet_address
nickname
picture
signup_methods
levels {
xp
level
user_level_chain {
id
name
punkga_config
}
}
authorizer_users_user_wallet {
address
}
creator {
id
pen_name
avatar_url
bio
}
user_quests_aggregate {
aggregate {
count
}
}
user_quests(order_by: {created_at:desc}, limit: 20) {
created_at
status
user_quest_rewards {
tx_hash
}
quest {
id
name
quests_campaign {
campaign_chain {
punkga_config
}
}
quests_i18n {
id
quest_id
language_id
data
i18n_language {
id
description
icon
is_main
symbol
}
}
reward
}
}
}
}
15 changes: 15 additions & 0 deletions src/modules/user/dto/create-artist-request.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';

export class CreateArtistRequestDto {
@ApiProperty()
pen_name: string;

@ApiProperty()
bio: string;

@ApiPropertyOptional()
avatar_url: string;

@ApiPropertyOptional({ type: 'string', format: 'binary' })
avatar: Express.Multer.File;
}
16 changes: 15 additions & 1 deletion src/modules/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ import { UpdateProfileRequestDto } from './dto/update-profile-request.dto';
import { UserService } from './user.service';
import { ReadChapterRequestDto } from './dto/read-chapter-request.dto';
import { ConnectWalletRequestDto } from './dto/connect-wallet-request.dto';
import { CreateArtistRequestDto } from './dto/create-artist-request.dto';

@Controller('user')
@ApiTags('user')
export class UserController {
constructor(private readonly userSvc: UserService) { }
constructor(private readonly userSvc: UserService) {}

@UseGuards(AuthGuard, RolesGuard)
@ApiBearerAuth()
Expand Down Expand Up @@ -78,4 +79,17 @@ export class UserController {
getAvailableQuests() {
return this.userSvc.getUserAvailableQuest();
}

@UseGuards(AuthGuard, RolesGuard)
@ApiBearerAuth()
@Roles(Role.User)
@Post('artist')
@ApiConsumes('multipart/form-data')
@UseInterceptors(AuthUserInterceptor, AnyFilesInterceptor())
createArtistProfile(
@Body() data: CreateArtistRequestDto,
@UploadedFiles() files: Array<Express.Multer.File>
) {
return this.userSvc.createArtistProfile(data, files);
}
}
47 changes: 47 additions & 0 deletions src/modules/user/user.graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,4 +379,51 @@ export class UserGraphql {
headers
);
}

createArtistProfile(variables: any) {
const headers = {
'x-hasura-admin-secret': this.configSvc.get<string>(
'graphql.adminSecret'
),
};

return this.graphqlSvc.query(
this.configSvc.get<string>('graphql.endpoint'),
'',
`mutation insert_creators_one($object: creators_insert_input = {}) {
insert_creators_one(object: $object) {
id
email
gender
}
}
`,
'insert_creators_one',
variables,
headers
);
}

async getUserInfo(variables: any) {
const headers = {
'x-hasura-admin-secret': this.configSvc.get<string>(
'graphql.adminSecret'
),
};

const result = await this.graphqlSvc.query(
this.configSvc.get<string>('graphql.endpoint'),
'',
`query authorizer_users_by_pk($id: bpchar!) {
authorizer_users_by_pk(id: $id) {
email
}
}`,
'authorizer_users_by_pk',
variables,
headers
);

return result.data.authorizer_users_by_pk;
}
}
38 changes: 38 additions & 0 deletions src/modules/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,42 @@ export class UserService {
};
}
}

async createArtistProfile(data: any, files: Array<Express.Multer.File>) {
const { userId, token } = ContextProvider.getAuthUser();

// get user email
const user = await this.userGraphql.getUserInfo({
id: userId,
});

const { pen_name, bio, avatar_url } = data;
let avatarUrl = data.avatar_url;
if (!avatar_url) {
// upload image
const avatar = files.find(
(file) => file.fieldname === 'avatar' && file.mimetype.includes('image')
);

// resize
const resized = await this.filesService.resize(avatar.buffer);
const s3SubFolder =
this.configService.get<string>('aws.s3SubFolder') || 'images';
const keyName = `${s3SubFolder}/user-${userId}/avatar.png`;
await this.filesService.uploadToS3(keyName, resized, 'image/png');

const s3Endpoint = this.configService.get<string>('aws.queryEndpoint');
avatarUrl = new URL(keyName, s3Endpoint).href;
}

// create artist profile
return this.userGraphql.createArtistProfile({
object: {
pen_name,
bio,
avatar_url: avatarUrl,
email: user.email,
},
});
}
}

0 comments on commit e785076

Please sign in to comment.