Skip to content

Commit

Permalink
Merge pull request #53 from aura-nw/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
harisato authored Sep 4, 2024
2 parents 12ac71b + b2c2ec5 commit 1cdfae5
Show file tree
Hide file tree
Showing 24 changed files with 388 additions and 413 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
table:
name: donate_history
schema: public
object_relationships:
- name: creator
using:
foreign_key_constraint_on: creator_id
- name: telegram_user
using:
foreign_key_constraint_on: telegram_id
1 change: 1 addition & 0 deletions hasura/metadata/databases/punkga-pg/tables/tables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- "!include public_chapters.yaml"
- "!include public_contest.yaml"
- "!include public_creators.yaml"
- "!include public_donate_history.yaml"
- "!include public_email_subscribe.yaml"
- "!include public_i18n.yaml"
- "!include public_languages.yaml"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE "public"."donate_history";
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CREATE TABLE "public"."donate_history" ("id" serial NOT NULL, "telegram_id" text NOT NULL, "creator_id" integer NOT NULL, "txn" text NOT NULL, "value" text NOT NULL, "created_at" timestamptz NOT NULL DEFAULT now(), "updated_at" timestamptz NOT NULL DEFAULT now(), PRIMARY KEY ("id") , FOREIGN KEY ("telegram_id") REFERENCES "public"."telegram_users"("telegram_id") ON UPDATE cascade ON DELETE cascade, FOREIGN KEY ("creator_id") REFERENCES "public"."creators"("id") ON UPDATE cascade ON DELETE cascade);
CREATE OR REPLACE FUNCTION "public"."set_current_timestamp_updated_at"()
RETURNS TRIGGER AS $$
DECLARE
_new record;
BEGIN
_new := NEW;
_new."updated_at" = NOW();
RETURN _new;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER "set_public_donate_history_updated_at"
BEFORE UPDATE ON "public"."donate_history"
FOR EACH ROW
EXECUTE PROCEDURE "public"."set_current_timestamp_updated_at"();
COMMENT ON TRIGGER "set_public_donate_history_updated_at" ON "public"."donate_history"
IS 'trigger to set value of column "updated_at" to current timestamp on row update';
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table "public"."donate_history" alter column "value" drop not null;
alter table "public"."donate_history" add column "value" text;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."donate_history" drop column "value" cascade;
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"."donate_history" add column "value" Integer
-- null;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table "public"."donate_history" add column "value" Integer
null;
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
-- Could not auto-generate a down migration.
-- Please write an appropriate down migration for the SQL below:
-- CREATE OR REPLACE FUNCTION update_show_album_fnc() RETURNS trigger AS $$
-- DECLARE
-- cnt integer;
-- BEGIN
-- SELECT count(*) INTO cnt FROM artworks a WHERE a.album_id = OLD.album_id;
-- IF cnt = 0 THEN
-- UPDATE albums SET show = false WHERE id = OLD.album_id;
-- END IF;
-- RETURN OLD;
-- END;
-- $$ LANGUAGE plpgsql;
--
-- CREATE OR REPLACE TRIGGER update_show_album
-- AFTER DELETE ON artworks
-- FOR EACH ROW
-- EXECUTE FUNCTION update_show_album_fnc();
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
CREATE OR REPLACE FUNCTION update_show_album_fnc() RETURNS trigger AS $$
DECLARE
cnt integer;
BEGIN
SELECT count(*) INTO cnt FROM artworks a WHERE a.album_id = OLD.album_id;
IF cnt = 0 THEN
UPDATE albums SET show = false WHERE id = OLD.album_id;
END IF;
RETURN OLD;
END;
$$ LANGUAGE plpgsql;

CREATE OR REPLACE TRIGGER update_show_album
AFTER DELETE ON artworks
FOR EACH ROW
EXECUTE FUNCTION update_show_album_fnc();
1 change: 1 addition & 0 deletions src/auth/auth.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class AuthGuard implements CanActivate {
userId: insertResult.data.insert_telegram_users_one.authorizer_user?.id,
roles: [Role.TelegramUser],
telegramUserId: insertResult.data.insert_telegram_users_one.id,
telegramId: user.id.toString(),
};

return true;
Expand Down
1 change: 1 addition & 0 deletions src/auth/dto/user.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export class UserDto {
roles: string[];
token: string;
telegramUserId?: string;
telegramId?: string;
}
7 changes: 6 additions & 1 deletion src/modules/album/album.graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ export class AlbumGraphql {
}
}
}
}
albums_aggregate(where: {creator_id: {_eq: $creator_id}}) {
aggregate {
count
}
}
}
`,
'list_album',
variables,
Expand Down
12 changes: 8 additions & 4 deletions src/modules/album/album.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ export class AlbumService {
thumbnail_url = uploadedUrl;
break;
case 'artworks':
artworks.push(uploadedUrl);
artworks.push({
url: uploadedUrl,
name: file.originalname,
});
break;
default:
break;
Expand All @@ -99,9 +102,10 @@ export class AlbumService {
if (updateResult.errors) return updateResult;
}

const artworkData = artworks.map((artworkUrl) => ({
const artworkData = artworks.map((artwork) => ({
album_id: albumId,
url: artworkUrl,
url: artwork.url,
name: artwork.name,
creator_id: creatorId,
}));
// insert
Expand Down Expand Up @@ -159,7 +163,7 @@ export class AlbumService {

const totalArtworks =
getAlbumResult.data.albums_by_pk.artworks_aggregate.aggregate.count;
if (show === true && Number(totalArtworks) === 0) show = false;
if (Boolean(show) === true && Number(totalArtworks) === 0) show = 'false';

let thumbnail_url = '';

Expand Down
4 changes: 2 additions & 2 deletions src/modules/album/dto/update-album-request.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export class UpdateAlbumRequestDto {
@ApiPropertyOptional({ type: 'string', format: 'binary' })
thumbnail: Express.Multer.File;

@ApiProperty()
show: boolean;
@ApiProperty({ default: 'true' })
show: string;
}
17 changes: 16 additions & 1 deletion src/modules/artwork/artwork.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { Role } from '../../auth/role.enum';
import { RolesGuard } from '../../auth/role.guard';
import { Roles } from '../../auth/roles.decorator';
import { AuthUserInterceptor } from '../../interceptors/auth-user.interceptor';
import { FileInterceptor } from '@nestjs/platform-express';
import { AnyFilesInterceptor, FileInterceptor } from '@nestjs/platform-express';
import { ArtworkService } from './artwork.service';
import { SetRequestTimeout } from '../../decorators/set-timeout.decorator';
import { ImportArtworkDto } from './dto/import-artwork.dto';
Expand All @@ -33,6 +33,7 @@ import {
UpdateArtworkParamDto,
} from './dto/update-artwork.dto';
import { DeleteArtworksDto } from './dto/delete-artworks.dto';
import { UploadArtworkDto } from './dto/upload-artwork.dto';

@Controller('artwork')
@ApiTags('artwork')
Expand All @@ -53,6 +54,20 @@ export class ArtworkController {
return this.artworkSvc.import(body, file);
}

@UseGuards(AuthGuard, RolesGuard)
@ApiBearerAuth()
@Post()
@ApiConsumes('multipart/form-data')
@UseInterceptors(AuthUserInterceptor, AnyFilesInterceptor())
@SetRequestTimeout()
@Roles(Role.Creator)
upload(
@Body() body: UploadArtworkDto,
@UploadedFiles() files: Array<Express.Multer.File>
) {
return this.artworkSvc.upload(body.album_id, files);
}

@UseGuards(AuthGuard, RolesGuard)
@ApiBearerAuth()
@Roles(Role.Creator)
Expand Down
Loading

0 comments on commit 1cdfae5

Please sign in to comment.