Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/update brand status #9

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: test_db
MYSQL_DATABASE: test_memorable_db
ports:
- "3307:3306"
command: ["mysqld", "--character-set-server=latin1", "--collation-server=latin1_swedish_ci"]
Expand Down
44 changes: 34 additions & 10 deletions init-project/db-user-schema-create.sql
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
CREATE DATABASE test_schema
CREATE DATABASE IF NOT EXISTS test_memorable_db
CHARACTER SET utf8mb4
COLLATE utf8mb4_bin;

use test_schema;
use test_memorable_db;


DROP TABLE IF EXISTS `invitation`;

ALTER TABLE `brand_status` DROP FOREIGN KEY `brand_status_ibfk_1`;

DROP TABLE IF EXISTS `brand`;
DROP TABLE IF EXISTS `user`;
DROP TABLE IF EXISTS `business_account`;
DROP TABLE IF EXISTS `brand_status`;

--
-- Table structure for table `business_account`
--

DROP TABLE IF EXISTS `business_account`;
CREATE TABLE `business_account` (
`id` varchar(255) NOT NULL,
`createdAt` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
Expand All @@ -24,8 +30,21 @@ CREATE TABLE `business_account` (
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

--
-- Table structure for table `brand_status`
--
CREATE TABLE `brand_status` (
`id` varchar(255) NOT NULL,
`status` varchar(255) NOT NULL,
`createdAt` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
`updatedAt` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6),
`brandId` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

DROP TABLE IF EXISTS `brand`;
--
-- Table structure for table `brand`
--
CREATE TABLE `brand` (
`id` varchar(255) NOT NULL,
`createdAt` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
Expand All @@ -36,15 +55,22 @@ CREATE TABLE `brand` (
`sector` text,
`adAccounts` text,
`socialAccounts` text,
`brandStatusId` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `FK_ce8346e2deaf4543dd3f83304a3` (`businessAccountId`),
CONSTRAINT `FK_ce8346e2deaf4543dd3f83304a3` FOREIGN KEY (`businessAccountId`) REFERENCES `business_account` (`id`)
CONSTRAINT `FK_ce8346e2deaf4543dd3f83304a3` FOREIGN KEY (`businessAccountId`) REFERENCES `business_account` (`id`),
KEY `FK_Brand_brandStatus` (`brandStatusId`),
CONSTRAINT `FK_Brand_brandStatus` FOREIGN KEY (`brandStatusId`) REFERENCES `brand_status` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

--
-- Table structure for table `user`
-- Brand Status modification to add foreign key
--
ALTER TABLE `brand_status` ADD FOREIGN KEY `FK_BrandStatus_Brand` (`brandId`) REFERENCES `brand`(`id`);

DROP TABLE IF EXISTS `user`;
--
-- Table structure for table `user`
--
CREATE TABLE `user` (
`id` varchar(255) NOT NULL,
`createdAt` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
Expand All @@ -69,8 +95,6 @@ CREATE TABLE `user` (
--
-- Table structure for table `invitation`
--

DROP TABLE IF EXISTS `invitation`;
CREATE TABLE `invitation` (
`id` varchar(255) NOT NULL,
`createdAt` datetime(6) NOT NULL DEFAULT CURRENT_TIMESTAMP(6),
Expand Down
19 changes: 16 additions & 3 deletions init-project/init-db-dump.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-- MySQL dump 10.13 Distrib 8.0.32, for Win64 (x86_64)
--
-- Host: 127.0.0.1 Database: test_schema
-- Host: 127.0.0.1 Database: test_memorable_db
-- ------------------------------------------------------
-- Server version 8.0.31

Expand All @@ -15,16 +15,29 @@
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;


--
-- Dumping data for table `brand_status`
--
use test_memorable_db;
LOCK TABLES `brand_status` WRITE;
/*!40000 ALTER TABLE `brand_status` DISABLE KEYS */;
INSERT INTO `brand_status` VALUES ('01H4618V8XGS613BS5BSPZP183','IN_PROGRESS','2023-10-01 16:46:00.580809','2023-10-01 16:46:00.580809','01H4618V8XGS613BS5BSPZP180');
/*!40000 ALTER TABLE `brand_status` ENABLE KEYS */;
UNLOCK TABLES;


--
-- Dumping data for table `brand`
--
use test_schema;
use test_memorable_db;
LOCK TABLES `brand` WRITE;
/*!40000 ALTER TABLE `brand` DISABLE KEYS */;
INSERT INTO `brand` VALUES ('01H4618V8XGS613BS5BSPZP180','2023-06-30 11:33:32.580809','2023-06-30 11:33:32.580809','Pharma Tecnologies','logoUrl','01H4616SGMFZ1GX71ZG5DCZMFD','PharmaceuticalsAndBiotechnology',NULL,NULL);
INSERT INTO `brand` VALUES ('01H4618V8XGS613BS5BSPZP180','2023-06-30 11:33:32.580809','2023-06-30 11:33:32.580809','Pharma Tecnologies','logoUrl','01H4616SGMFZ1GX71ZG5DCZMFD','PharmaceuticalsAndBiotechnology',NULL,NULL,'01H4618V8XGS613BS5BSPZP183');
/*!40000 ALTER TABLE `brand` ENABLE KEYS */;
UNLOCK TABLES;


--
-- Dumping data for table `business_account`
--
Expand Down
16 changes: 16 additions & 0 deletions schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type Brand {
adAccounts: [String!]
socialAccounts: [String!]
businessAccount: BusinessAccount!
brandStatus: BrandStatus!
}

enum Sector {
Expand Down Expand Up @@ -123,6 +124,14 @@ enum Sector {
CorporateTrainingAndDevelopment
}

type BrandStatus {
id: ID!
createdAt: DateTime!
updatedAt: DateTime!
status: String!
brand: Brand!
}

type Mutation {
"""Creates a business Account for the provided business admin"""
createBrand(input: CreateBrandInput!): Brand!
Expand All @@ -133,6 +142,9 @@ type Mutation {
"""Updates assets of a brand"""
updateBrandAssets(input: BrandAssetsInput!, brandId: String!): Brand!

"""Updates status of a brand"""
updateBrandStatus(input: BrandStatusInput!, brandId: String!): Brand!

"""Uploads brand logo"""
requestLogoUploadData(input: UploadRequestInput!): UploadDataResponse!

Expand Down Expand Up @@ -215,6 +227,10 @@ enum SocialAccountType {
TiktokAccount
}

input BrandStatusInput {
status: String!
}

type UploadDataResponse {
id: String!
originalUrl: String!
Expand Down
1 change: 1 addition & 0 deletions src/common/errors/ErrorCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,5 @@ export enum ErrorMsg {
PASSWORD_LENGTH_ERROR = "PASSWORD_LENGTH_ERROR",
PASSWORD_TOO_WEAK = "PASSWORD_TOO_WEAK",
FIELD_STRING_INVALID = "FIELD_STRING_INVALID",
INVALID_BRAND_STATUS = "INVALID_BRAND_STATUS"
}
2 changes: 0 additions & 2 deletions src/graphql/graphqlSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {buildSchema, registerEnumType} from "type-graphql";
import {Container} from "typedi";
import {ErrorCode, ErrorMsg} from "../common/errors/ErrorCode";
import {SortType} from "../common/queries/Sort";
import {BrandStatus} from "../intelligentSuite/brands/entities/BrandStatus";
import {BrandResolver} from "../intelligentSuite/brands/resolvers/BrandResolver";
import {BusinessAccountResolver} from "../intelligentSuite/businessAccounts/resolvers/BusinessAccountResolver";
import {AdAccountType, SocialAccountType} from "../intelligentSuite/common/entities/Assets";
Expand All @@ -27,7 +26,6 @@ const resolvers = [UserResolver, BusinessAccountResolver, BrandResolver, Invitat

export const graphqlSchema = async (emitSchema = false, usePubSub = true) => {
registerEnumType(OrderingDirection, {name: "OrderingDirection", description: "Ordering direction"});
registerEnumType(BrandStatus, {name: "BrandStatus", description: "Brand Status"});
registerEnumType(LabeledMetricValue, {name: "LabeledMetricValue", description: "Labeled Metric Value"});
registerEnumType(ErrorCode, {name: "ErrorCode", description: "Api error codes"});
registerEnumType(FileType, {name: "FileType"});
Expand Down
8 changes: 7 additions & 1 deletion src/intelligentSuite/brands/entities/Brand.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {Field, ObjectType} from "type-graphql";
import {Column, Entity, ManyToOne} from "typeorm";
import {Column, Entity, JoinColumn, ManyToOne, OneToMany, OneToOne} from "typeorm";
import {BaseEntity} from "../../../common/entities/BaseEntity";
import {BusinessAccount} from "../../businessAccounts/entities/BusinessAccount";
import {Sector} from "../../common/entities/Sector";
import {CreateBrandInput, UpdateBrandInput} from "../input/BrandInput";
import BrandStatus from "./BrandStatus";

@ObjectType()
@Entity()
Expand Down Expand Up @@ -32,6 +33,11 @@ export default class Brand extends BaseEntity {
@Field(() => BusinessAccount)
businessAccount!: BusinessAccount;

@OneToOne(() => BrandStatus, (brandStatus: BrandStatus) => brandStatus.id)
@JoinColumn()
@Field(() => BrandStatus)
brandStatus?: BrandStatus;

static create(businessAccount: BusinessAccount, input: CreateBrandInput) {
const brand = new Brand();
brand.setId();
Expand Down
36 changes: 35 additions & 1 deletion src/intelligentSuite/brands/entities/BrandStatus.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,40 @@
export enum BrandStatus {
import {Column, Entity, JoinColumn, ManyToOne, OneToMany, OneToOne} from "typeorm";
import {Field, ObjectType} from "type-graphql";
import Brand from "./Brand";
import {BaseEntity} from "../../../common/entities/BaseEntity";
import {BrandStatusInput} from "../input/BrandInput";
import {BadRequestError} from "../../../common/errors/BadRequestError";
import {ErrorMsg} from "../../../common/errors/ErrorCode";

export enum ValidBrandStatus {
IN_PROGRESS = "IN_PROGRESS",
DATA_READY = "DATA_READY",
MODEL_TRAINING = "MODEL_TRAINING",
READY = "READY",
}

@ObjectType()
@Entity()
export default class BrandStatus extends BaseEntity {

@Column()
@Field()
status!: string

@OneToOne(() => Brand, (brand: Brand) => brand.id)
@Field(() => Brand)
brand!: Brand;

static create(brand: Brand, input: BrandStatusInput) {
const brandStatus = new BrandStatus()
brandStatus.setId();
brandStatus.status = input.status
brandStatus.brand = brand

return brandStatus
}

isSameStatus(status: string){
return this.status == status
}
}
8 changes: 8 additions & 0 deletions src/intelligentSuite/brands/input/BrandInput.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Field, InputType, Int} from "type-graphql";
import {AdAccountType, SocialAccountType} from "../../common/entities/Assets";
import {Sector} from "../../common/entities/Sector";
import {ValidBrandStatus} from "../entities/BrandStatus";

@InputType()
export class CreateBrandInput {
Expand Down Expand Up @@ -30,6 +31,13 @@ export class BrandAssetsInput {
@Field(() => [SocialAccountInput], {nullable: true})
socialAccount?: SocialAccountInput[];
}

@InputType()
export class BrandStatusInput {
@Field(() => String)
status!: string;
}

@InputType()
export class SocialAccountInput {
@Field(() => Int)
Expand Down
10 changes: 9 additions & 1 deletion src/intelligentSuite/brands/repository/BrandQuerySet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import {BaseEntity} from "../../../common/entities/BaseEntity";
import {QuerySet} from "../../../common/repositories/QuerySet";
import {UserQuerySet} from "../../users/repositories/UserQuerySet";
import {BrandStatusQuerySet} from "./BrandStatusQuerySet";

export class BrandQuerySet<T extends BaseEntity> extends QuerySet<T> {}
export class BrandQuerySet<T extends BaseEntity> extends QuerySet<T> {

withBrandStatus(): this {
this.queryBuilder = this.leftJoinRelation(BrandStatusQuerySet, "brandStatus", "brandStatus", true).getQueryBuilder();
return this;
}
}
4 changes: 4 additions & 0 deletions src/intelligentSuite/brands/repository/BrandRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export class BrandRepository extends BaseRepository<Brand> {
super(repository);
}

async getByIDWithStatus(brandId: string){
return this.getQuerySet().filterById(brandId).withBrandStatus().getOne()
}

getQuerySet(): BrandQuerySet<Brand> {
const queryBuilder = this.repository.createQueryBuilder("Brand");
return new BrandQuerySet(queryBuilder, "Brand");
Expand Down
4 changes: 4 additions & 0 deletions src/intelligentSuite/brands/repository/BrandStatusQuerySet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {BaseEntity} from "../../../common/entities/BaseEntity";
import {QuerySet} from "../../../common/repositories/QuerySet";

export class BrandStatusQuerySet<T extends BaseEntity> extends QuerySet<T> {}
20 changes: 20 additions & 0 deletions src/intelligentSuite/brands/repository/BrandStatusRepository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import {Service} from "typedi";
import {Repository} from "typeorm";
import {InjectRepository} from "typeorm-typedi-extensions";
import {BaseRepository} from "../../../common/repositories/BaseRepository";
import Brand from "../entities/Brand";
import {BrandQuerySet} from "./BrandQuerySet";
import BrandStatus from "../entities/BrandStatus";
import {BrandStatusQuerySet} from "./BrandStatusQuerySet";

@Service()
export class BrandStatusRepository extends BaseRepository<BrandStatus> {
constructor(@InjectRepository(BrandStatus) private repository: Repository<BrandStatus>) {
super(repository);
}

getQuerySet(): BrandStatusQuerySet<BrandStatus> {
const queryBuilder = this.repository.createQueryBuilder("BrandStatus");
return new BrandQuerySet(queryBuilder, "BrandStatus");
}
}
13 changes: 12 additions & 1 deletion src/intelligentSuite/brands/resolvers/BrandResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ import {UploadDataResponse} from "../../fileHandler/entities/UploadDataResponse"
import {User} from "../../users/entities/User";
import Brand from "../entities/Brand";
import {BrandAssetsResponse} from "../entities/BrandAssetsResponse";
import {BrandAssetsInput, CreateBrandInput, UpdateBrandInput} from "../input/BrandInput";
import {BrandAssetsInput, BrandStatusInput, CreateBrandInput, UpdateBrandInput} from "../input/BrandInput";
import {BrandAccountsService} from "../service/BrandAccountsService";
import {BrandService} from "../service/BrandService";
import {BrandStatusService} from "../service/BrandStatusService";

@Service()
@Resolver()
export class BrandResolver {
constructor(
private readonly brandService: BrandService,
private readonly brandAccountsService: BrandAccountsService,
private readonly brandStatusService: BrandStatusService,
) {}

@Mutation((_returns) => Brand, {
Expand Down Expand Up @@ -43,6 +45,15 @@ export class BrandResolver {
return await this.brandAccountsService.updateBrandAssets(user, brandId, input);
}

@Mutation((_returns) => Brand, {description: "Updates status of a brand"})
async updateBrandStatus(
@CurrentUser() user: User,
@Arg("brandId") brandId: string,
@Arg("input") input: BrandStatusInput,
) {
return await this.brandService.updateBrandStatus(user, brandId, input);
}

@Mutation((_returns) => UploadDataResponse, {description: "Uploads brand logo"})
async requestLogoUploadData(@CurrentUser() user: User, @Arg("input") input: UploadRequestInput) {
return await this.brandService.getLogoUploadData(user, input);
Expand Down
Loading