Skip to content

Commit

Permalink
Merge branch 'feat/creator-portal' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
harisato committed Aug 16, 2024
2 parents 338c2aa + 3af35e0 commit 08f1f93
Show file tree
Hide file tree
Showing 14 changed files with 394 additions and 75 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Could not auto-generate a down migration.
-- Please write an appropriate down migration for the SQL below:
-- alter table "public"."artworks" add column "name" text
-- null;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table "public"."artworks" add column "name" text
null;
53 changes: 52 additions & 1 deletion src/modules/album/album.controller.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import {
Body,
Controller,
Delete,
Get,
Param,
Post,
Put,
Query,
UploadedFiles,
UseGuards,
UseInterceptors,
} from '@nestjs/common';
import { AnyFilesInterceptor } from '@nestjs/platform-express';
import { ApiBearerAuth, ApiConsumes, ApiTags } from '@nestjs/swagger';
import {
ApiBearerAuth,
ApiConsumes,
ApiOperation,
ApiTags,
} from '@nestjs/swagger';

import { AuthGuard } from '../../auth/auth.guard';
import { Role } from '../../auth/role.enum';
Expand All @@ -19,6 +27,11 @@ import { AuthUserInterceptor } from '../../interceptors/auth-user.interceptor';
import { AlbumService } from './album.service';
import { CreateAlbumRequestDto } from './dto/create-album-request.dto';
import { QueryAlbumDto } from './dto/query-album-query.dto';
import { DetailAlbumParamDto } from './dto/detail-album-request.dto';
import {
UpdateAlbumParamDto,
UpdateAlbumRequestDto,
} from './dto/update-album-request.dto';

@Controller('album')
@ApiTags('album')
Expand All @@ -29,15 +42,27 @@ export class AlbumController {
@UseGuards(AuthGuard, RolesGuard)
@ApiBearerAuth()
@Roles(Role.Creator)
@ApiOperation({ summary: 'list album - creator role' })
@UseInterceptors(AuthUserInterceptor)
list(@Query() query: QueryAlbumDto) {
return this.albumSvc.getAll(query);
}

@Get(':id')
@UseGuards(AuthGuard, RolesGuard)
@ApiBearerAuth()
@Roles(Role.Creator)
@ApiOperation({ summary: 'album detail - creator role' })
@UseInterceptors(AuthUserInterceptor)
detailAlbumDetail(@Param() param: DetailAlbumParamDto) {
return this.albumSvc.getDetail(param.id);
}

@UseGuards(AuthGuard, RolesGuard)
@ApiBearerAuth()
@Roles(Role.Creator)
@Post()
@ApiOperation({ summary: 'create album - creator role' })
@ApiConsumes('multipart/form-data')
@UseInterceptors(AuthUserInterceptor, AnyFilesInterceptor())
create(
Expand All @@ -46,4 +71,30 @@ export class AlbumController {
) {
return this.albumSvc.create(data, files);
}

@UseGuards(AuthGuard, RolesGuard)
@ApiBearerAuth()
@Roles(Role.Creator)
@Put(':id')
@ApiOperation({ summary: 'update album - creator role' })
@ApiConsumes('multipart/form-data')
@UseInterceptors(AuthUserInterceptor, AnyFilesInterceptor())
update(
@Param() param: UpdateAlbumParamDto,
@Body() data: UpdateAlbumRequestDto,
@UploadedFiles() files: Array<Express.Multer.File>
) {
return this.albumSvc.update(param.id, data, files);
}

@UseGuards(AuthGuard, RolesGuard)
@ApiBearerAuth()
@Roles(Role.Creator)
@Delete(':id')
@ApiOperation({ summary: 'delete album - creator role' })
@ApiConsumes('multipart/form-data')
@UseInterceptors(AuthUserInterceptor, AnyFilesInterceptor())
delete(@Param() param: UpdateAlbumParamDto) {
return this.albumSvc.delete(param.id);
}
}
122 changes: 52 additions & 70 deletions src/modules/album/album.graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export class AlbumGraphql {
'',
`query list_album($creator_id: Int!, $limit: Int = 20, $offset: Int = 0) {
default_album: albums_by_pk(id: 1) {
id
name
show
disable
Expand All @@ -31,6 +32,7 @@ export class AlbumGraphql {
}
}
albums(where: {creator_id: {_eq: $creator_id}}, limit: $limit, offset: $offset) {
id
name
show
disable
Expand All @@ -49,49 +51,64 @@ export class AlbumGraphql {
);
}

insert(variables: any) {
albumDetail(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_albums_one($object: albums_insert_input = {}) {
insert_albums_one(object: $object) {
`query album_detail($id: Int!, $creator_id: Int!) {
albums(where: {id: {_eq: $id}, creator_id: {_eq: $creator_id}}) {
id
name
description
thumbnail_url
show
disable
artworks {
id
name
url
created_at
}
}
}`,
'insert_albums_one',
}
`,
'album_detail',
variables,
headers
);
}

insertArtworks(variables: any) {
albumByPk(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_artworks($objects: [artworks_insert_input!] = {}) {
insert_artworks(objects: $objects) {
affected_rows
`query albums_by_pk($id: Int!) {
albums_by_pk(id: $id) {
creator_id
artworks_aggregate {
aggregate {
count
}
}
}
}`,
'insert_artworks',
'albums_by_pk',
variables,
headers
);
}

update(variables: any) {
insert(variables: any) {
const headers = {
'x-hasura-admin-secret': this.configSvc.get<string>(
'graphql.adminSecret'
Expand All @@ -101,111 +118,76 @@ export class AlbumGraphql {
return this.graphqlSvc.query(
this.configSvc.get<string>('graphql.endpoint'),
'',
`mutation update_albums_by_pk($id: Int!, $data: albums_set_input = {}) {
update_albums_by_pk(pk_columns: {id: $id}, _set: $data) {
updated_at
`mutation insert_albums_one($object: albums_insert_input = {}) {
insert_albums_one(object: $object) {
id
}
}`,
'update_albums_by_pk',
'insert_albums_one',
variables,
headers
);
}

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

return this.graphqlSvc.query(
this.configSvc.get<string>('graphql.endpoint'),
'',
`query launchpad_by_pk($id: Int!) {
launchpad_by_pk(id: $id) {
status
contract_address
fund
`mutation delete_albums_by_pk($id: Int!) {
delete_albums_by_pk(id: $id) {
id
slug
launchpad_creator {
avatar_url
bio
name
pen_name
slug
wallet_address
}
launchpad_i18ns {
id
language_id
data
}
featured_images
creator_id
}
}`,
'launchpad_by_pk',
'delete_albums_by_pk',
variables,
headers
);
}

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

return this.graphqlSvc.query(
this.configSvc.get<string>('graphql.endpoint'),
'',
`query launchpad($slug: String!) {
launchpad(where: {slug: {_eq: $slug}}) {
status
contract_address
fund
id
slug
launchpad_creator {
avatar_url
bio
name
pen_name
slug
wallet_address
}
launchpad_i18ns {
id
language_id
data
}
featured_images
creator_id
`mutation insert_artworks($objects: [artworks_insert_input!] = {}) {
insert_artworks(objects: $objects) {
affected_rows
}
}`,
'launchpad',
'insert_artworks',
variables,
headers
);
}

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

return this.graphqlSvc.query(
this.configSvc.get<string>('graphql.endpoint'),
'',
`mutation insert_i18n($objects: [i18n_insert_input!] = {}) {
insert_i18n(on_conflict: {constraint: i18n_launchpad_id_language_id_key, update_columns: data}, objects: $objects) {
`mutation update_albums_by_pk($id: Int!, $data: albums_set_input = {}, $creator_id: Int!) {
update_albums(where: {id: {_eq: $id}, creator_id: {_eq: $creator_id}}, _set: $data) {
affected_rows
}
}`,
'insert_i18n',
}
`,
'update_albums_by_pk',
variables,
headers
);
Expand Down
Loading

0 comments on commit 08f1f93

Please sign in to comment.