From d4debaaf20e6ec8452832e55b6091f3561220b67 Mon Sep 17 00:00:00 2001 From: simaomeyrerdooca Date: Thu, 4 Jul 2024 14:02:36 -0300 Subject: [PATCH 01/14] feat: add modulo de liveShop --- src/env.d.ts | 1 + src/index.ts | 4 +- src/modules/live-shop/LiveShopQueries.ts | 67 +++++++++++++++++++ .../live-shop/LiveShopRepositoryGql.ts | 13 ++++ .../live-shop/LiveShopRepositoryJson.ts | 10 +++ src/modules/live-shop/LiveShopService.ts | 22 ++++++ src/modules/live-shop/LiveShopTypes.ts | 60 +++++++++++++++++ src/services/broadcast/broadcast-service.ts | 1 + 8 files changed, 177 insertions(+), 1 deletion(-) create mode 100644 src/modules/live-shop/LiveShopQueries.ts create mode 100644 src/modules/live-shop/LiveShopRepositoryGql.ts create mode 100644 src/modules/live-shop/LiveShopRepositoryJson.ts create mode 100644 src/modules/live-shop/LiveShopService.ts create mode 100644 src/modules/live-shop/LiveShopTypes.ts diff --git a/src/env.d.ts b/src/env.d.ts index 7dd5fd3..d0f08f4 100644 --- a/src/env.d.ts +++ b/src/env.d.ts @@ -28,6 +28,7 @@ interface shop { shop?: any products?: any user?: any + live_shop?: any } } diff --git a/src/index.ts b/src/index.ts index d018dde..1a9d686 100644 --- a/src/index.ts +++ b/src/index.ts @@ -23,6 +23,7 @@ import { ProductService } from './modules/product/ProductService' import { UserService } from './modules/user/UserService' import { FreightService } from './modules/freight/FreightService' import { BuyTogetherService } from './modules/buy-together/BuyTogetherService' +import { LiveShopService } from './modules/live-shop/LiveShopService' import { SeoServiceFactory } from './services/seo/SeoServiceFactory' import { CookieService } from './services/CookieService' @@ -56,5 +57,6 @@ export { CookieService, Socket, NavigationService, - BuyTogetherService + BuyTogetherService, + LiveShopService } diff --git a/src/modules/live-shop/LiveShopQueries.ts b/src/modules/live-shop/LiveShopQueries.ts new file mode 100644 index 0000000..3276ec2 --- /dev/null +++ b/src/modules/live-shop/LiveShopQueries.ts @@ -0,0 +1,67 @@ +export class LiveShopQueries { + fields: null | string[] + + constructor(fields: string[]) { + this.fields = fields || this.defaultFields() + } + + private getImageFields() { + return '{alt, src}' + } + + private getMessageFields() { + return '{title, content}' + } + + private getDiscountFields() { + return '{type, value}' + } + + private getVariationFields() { + return ` + { + id, + discount ${this.getDiscountFields()} + }` + } + + private getProductFields() { + return ` + { + id, + discount ${this.getDiscountFields()}, + variations ${this.getVariationFields()} + }` + } + + defaultFields() { + return [ + 'id', + 'name', + 'status', + 'urlLive', + 'title', + `banner ${this.getImageFields()}`, + `messages ${this.getMessageFields()}`, + `products ${this.getProductFields()}`, + 'alertVisible', + 'chatVisible', + 'isActive', + 'createdAt', + 'updatedAt' + ] + } + + getFields() { + return this.fields.join() + } + + getOneFullQuery() { + return ` + query LiveShop($filter: FilterLiveShop){ + liveShop(filter: $filter){ + ${this.getFields()} + } + }` + } +} diff --git a/src/modules/live-shop/LiveShopRepositoryGql.ts b/src/modules/live-shop/LiveShopRepositoryGql.ts new file mode 100644 index 0000000..f796010 --- /dev/null +++ b/src/modules/live-shop/LiveShopRepositoryGql.ts @@ -0,0 +1,13 @@ +import { getClient } from '../../services/GraphqlService' +import { LiveShopQueries } from './LiveShopQueries' +import { LiveShop, LiveShopFields, LiveShopResponse } from './LiveShopTypes' + +export class LiveShopRepositoryGql { + static async getByHash(hash: string, fields?: LiveShopFields[]): Promise { + const liveShopQuery = new LiveShopQueries(fields) + const fullQuery: string = liveShopQuery.getOneFullQuery() + const { liveShop }: LiveShopResponse = await getClient().query(fullQuery, { filter: { hash } }) + + return liveShop + } +} diff --git a/src/modules/live-shop/LiveShopRepositoryJson.ts b/src/modules/live-shop/LiveShopRepositoryJson.ts new file mode 100644 index 0000000..fdd550d --- /dev/null +++ b/src/modules/live-shop/LiveShopRepositoryJson.ts @@ -0,0 +1,10 @@ +import liveShopJsonMock from '../../mocks/live-shop/live-shop.json' +import { LiveShop } from './LiveShopTypes' + +export class LiveShopRepositoryJson { + static async getByHash(hash: string, fields?: string[]): Promise { + const liveShop = liveShopJsonMock + const result = liveShop.find(item => item.hashRoom === hash) + return result + } +} diff --git a/src/modules/live-shop/LiveShopService.ts b/src/modules/live-shop/LiveShopService.ts new file mode 100644 index 0000000..5515005 --- /dev/null +++ b/src/modules/live-shop/LiveShopService.ts @@ -0,0 +1,22 @@ +import { BroadcastService } from '../../services/broadcast/broadcast-service' +import { LiveShopRepositoryGql } from './LiveShopRepositoryGql' +import { LiveShopRepositoryJson } from './LiveShopRepositoryJson' +import { LiveShop, LiveShopFields } from './LiveShopTypes' +import liveShopMock from '../../mocks/live-shop/live-shop.json' + +shop_ctx.mock.live_shop = liveShopMock + +const Repository = () => (shop_ctx.mock?.live_shop ? LiveShopRepositoryJson : LiveShopRepositoryGql) + +export class LiveShopService { + static async getByHash(hash: string, fields?: LiveShopFields[]): Promise { + try { + const result: LiveShop = await Repository().getByHash(hash, fields) + BroadcastService.emit('LiveShop', result) + + return result + } catch (error) { + throw new Error(error?.message) + } + } +} diff --git a/src/modules/live-shop/LiveShopTypes.ts b/src/modules/live-shop/LiveShopTypes.ts new file mode 100644 index 0000000..e45939b --- /dev/null +++ b/src/modules/live-shop/LiveShopTypes.ts @@ -0,0 +1,60 @@ +export type LiveShopFields = + | 'id' + | 'hashRoom' + | 'name' + | 'status' + | 'urlLive' + | 'title' + | 'banner' + | 'products' + | 'messages' + | 'alertVisible' + | 'chatVisible' + | 'isActive' + | 'createdAt' + | 'updatedAt' + +export interface LiveShopImage { + src: string + alt: string +} + +export interface LiveShopDiscount { + type: string + value: number +} + +export interface LiveShopMessage { + title: string + content: string +} + +export interface LiveShopVariation { + id: number + discount: LiveShopDiscount +} +export interface LiveShopProduct { + id: number + discount: LiveShopDiscount + variations: LiveShopVariation[] +} + +export interface LiveShop { + id: number + hashRoom: string + name: string + status: string + urlLive: string + title: string + banner: LiveShopImage + products: LiveShopProduct[] + messages: LiveShopMessage[] + alertVisible: boolean + chatVisible: boolean + isActive: boolean + createdAt: string + updatedAt: string +} +export interface LiveShopResponse { + liveShop: LiveShop +} diff --git a/src/services/broadcast/broadcast-service.ts b/src/services/broadcast/broadcast-service.ts index 9ae6542..afb8911 100644 --- a/src/services/broadcast/broadcast-service.ts +++ b/src/services/broadcast/broadcast-service.ts @@ -6,6 +6,7 @@ export type BroadcastEvents = | 'Category' | 'Freight' | 'LandingPages' + | 'LiveShop' | 'Menu' | 'Newsletter' | 'Pages' From 851d7b5663ec4d7090abbca99deb87c2a9b86eb6 Mon Sep 17 00:00:00 2001 From: simaomeyrerdooca Date: Thu, 4 Jul 2024 14:02:53 -0300 Subject: [PATCH 02/14] =?UTF-8?q?feat:=20adi=C3=A7=C3=A3o=20dos=20testes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mocks/live-shop/live-shop.json | 43 +++++++++++++++++++ src/modules/live-shop/LiveShopService.ts | 3 -- .../live-shop/__test__/live-shop.test.ts | 12 ++++++ 3 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 src/mocks/live-shop/live-shop.json create mode 100644 src/modules/live-shop/__test__/live-shop.test.ts diff --git a/src/mocks/live-shop/live-shop.json b/src/mocks/live-shop/live-shop.json new file mode 100644 index 0000000..a6629f1 --- /dev/null +++ b/src/mocks/live-shop/live-shop.json @@ -0,0 +1,43 @@ +[ + { + "id": 1, + "hashRoom": "abc123", + "name": "Super Live Shop", + "status": "active", + "urlLive": "https://www.youtube.com/watch?v=J-K0cF0BCx4", + "title": "Bem vindo a Super Live Shop!", + "banner": { + "src": "https://picsum.photos/200", + "alt": "Banner Image" + }, + "products": [ + { + "id": 101, + "discount": { + "type": "percentage", + "value": 10 + }, + "variations": [ + { + "id": 1001, + "discount": { + "type": "fixed", + "value": 5 + } + } + ] + } + ], + "messages": [ + { + "title": "Boas vindas!", + "content": "Bem vindo a primeira live shop!" + } + ], + "alertVisible": true, + "chatVisible": false, + "isActive": true, + "createdAt": "2024-07-03T12:00:00Z", + "updatedAt": "2024-07-03T12:00:00Z" + } +] diff --git a/src/modules/live-shop/LiveShopService.ts b/src/modules/live-shop/LiveShopService.ts index 5515005..842c39b 100644 --- a/src/modules/live-shop/LiveShopService.ts +++ b/src/modules/live-shop/LiveShopService.ts @@ -2,9 +2,6 @@ import { BroadcastService } from '../../services/broadcast/broadcast-service' import { LiveShopRepositoryGql } from './LiveShopRepositoryGql' import { LiveShopRepositoryJson } from './LiveShopRepositoryJson' import { LiveShop, LiveShopFields } from './LiveShopTypes' -import liveShopMock from '../../mocks/live-shop/live-shop.json' - -shop_ctx.mock.live_shop = liveShopMock const Repository = () => (shop_ctx.mock?.live_shop ? LiveShopRepositoryJson : LiveShopRepositoryGql) diff --git a/src/modules/live-shop/__test__/live-shop.test.ts b/src/modules/live-shop/__test__/live-shop.test.ts new file mode 100644 index 0000000..c12e856 --- /dev/null +++ b/src/modules/live-shop/__test__/live-shop.test.ts @@ -0,0 +1,12 @@ +import 'isomorphic-fetch' +import { LiveShop } from '../LiveShopTypes' +import { LiveShopService } from '../LiveShopService' + +const HASH_FILTER = 'abc123' + +describe('Live Shop Module', () => { + it('Should get live shop by hash with all fields successfully', async () => { + const liveShop: LiveShop = await LiveShopService.getByHash(HASH_FILTER) + expect(liveShop.hashRoom).toEqual(HASH_FILTER) + }) +}) From 3cbd4e5b35dd1ca34f8c7c7dbca618d7ea67c786 Mon Sep 17 00:00:00 2001 From: simaomeyrerdooca Date: Thu, 4 Jul 2024 15:26:56 -0300 Subject: [PATCH 03/14] =?UTF-8?q?refactor:=20adi=C3=A7=C3=A3o=20do=20getOn?= =?UTF-8?q?e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jest.config.js | 2 +- src/mocks/live-shop/live-shop.json | 5 +++-- src/modules/live-shop/LiveShopQueries.ts | 4 ++-- src/modules/live-shop/LiveShopRepositoryGql.ts | 7 +++++-- src/modules/live-shop/LiveShopRepositoryJson.ts | 14 +++++++++++--- src/modules/live-shop/LiveShopService.ts | 12 +++++++++++- src/modules/live-shop/LiveShopTypes.ts | 2 +- src/modules/live-shop/__test__/live-shop.test.ts | 6 ++++++ 8 files changed, 40 insertions(+), 12 deletions(-) diff --git a/jest.config.js b/jest.config.js index 0d04200..9b9fc0a 100644 --- a/jest.config.js +++ b/jest.config.js @@ -13,7 +13,7 @@ module.exports = { shop_ctx: { api_url: 'https://api-storefront.dchomolog.dooca.store/', token: - 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzaG9wX2lkIjoxMDM3NzksInR5cGUiOiJhZG1pbiIsImVtYWlsIjoic2ltYW8ubWV5cmVyQGJhZ3kuY29tLmJyIiwiZmlyc3RfbmFtZSI6IlNpbVx1MDBlM28iLCJhY3RpdmUiOnRydWUsImlhdCI6MTY5NTE1MjU2NX0.56NBX4cX4-fAt0CehPUNqCSMs3OTa617ImXlyZQ8nRA', + 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzaG9wX2lkIjoxMDM3Nzl9.aN9JQNFDsB2bZ56KuTSg9F0G8lmOqK59XEd_VXhaa5M', domain: 'sapato-do-simon.homolog.bagypro.com', mock: {} } diff --git a/src/mocks/live-shop/live-shop.json b/src/mocks/live-shop/live-shop.json index a6629f1..3a038ce 100644 --- a/src/mocks/live-shop/live-shop.json +++ b/src/mocks/live-shop/live-shop.json @@ -3,7 +3,8 @@ "id": 1, "hashRoom": "abc123", "name": "Super Live Shop", - "status": "active", + "slug": "super-live-shop", + "status": "inLive", "urlLive": "https://www.youtube.com/watch?v=J-K0cF0BCx4", "title": "Bem vindo a Super Live Shop!", "banner": { @@ -14,7 +15,7 @@ { "id": 101, "discount": { - "type": "percentage", + "type": "markup", "value": 10 }, "variations": [ diff --git a/src/modules/live-shop/LiveShopQueries.ts b/src/modules/live-shop/LiveShopQueries.ts index 3276ec2..4703985 100644 --- a/src/modules/live-shop/LiveShopQueries.ts +++ b/src/modules/live-shop/LiveShopQueries.ts @@ -20,7 +20,7 @@ export class LiveShopQueries { private getVariationFields() { return ` { - id, + variationId, discount ${this.getDiscountFields()} }` } @@ -28,7 +28,7 @@ export class LiveShopQueries { private getProductFields() { return ` { - id, + productId, discount ${this.getDiscountFields()}, variations ${this.getVariationFields()} }` diff --git a/src/modules/live-shop/LiveShopRepositoryGql.ts b/src/modules/live-shop/LiveShopRepositoryGql.ts index f796010..ec813c7 100644 --- a/src/modules/live-shop/LiveShopRepositoryGql.ts +++ b/src/modules/live-shop/LiveShopRepositoryGql.ts @@ -3,10 +3,13 @@ import { LiveShopQueries } from './LiveShopQueries' import { LiveShop, LiveShopFields, LiveShopResponse } from './LiveShopTypes' export class LiveShopRepositoryGql { - static async getByHash(hash: string, fields?: LiveShopFields[]): Promise { + static async getOne( + filter: { filter: { id?: number; hash?: string; slug?: string } }, + fields?: LiveShopFields[] + ): Promise { const liveShopQuery = new LiveShopQueries(fields) const fullQuery: string = liveShopQuery.getOneFullQuery() - const { liveShop }: LiveShopResponse = await getClient().query(fullQuery, { filter: { hash } }) + const { liveShop }: LiveShopResponse = await getClient().query(fullQuery, { ...filter }) return liveShop } diff --git a/src/modules/live-shop/LiveShopRepositoryJson.ts b/src/modules/live-shop/LiveShopRepositoryJson.ts index fdd550d..c095d82 100644 --- a/src/modules/live-shop/LiveShopRepositoryJson.ts +++ b/src/modules/live-shop/LiveShopRepositoryJson.ts @@ -2,9 +2,17 @@ import liveShopJsonMock from '../../mocks/live-shop/live-shop.json' import { LiveShop } from './LiveShopTypes' export class LiveShopRepositoryJson { - static async getByHash(hash: string, fields?: string[]): Promise { + static async getOne(filter: { id?: number; hash?: string; slug?: string }, fields?: string[]): Promise { const liveShop = liveShopJsonMock - const result = liveShop.find(item => item.hashRoom === hash) - return result + const liveShopResult = liveShop.find( + item => + (filter.hash && item.hashRoom === filter.hash) || + (filter.id && item.id === filter.id) || + (filter.slug && item.slug === filter.slug) + ) + if (!liveShopResult) { + throw new Error('Live Shop not found') + } + return liveShopResult } } diff --git a/src/modules/live-shop/LiveShopService.ts b/src/modules/live-shop/LiveShopService.ts index 842c39b..7a977a1 100644 --- a/src/modules/live-shop/LiveShopService.ts +++ b/src/modules/live-shop/LiveShopService.ts @@ -8,7 +8,17 @@ const Repository = () => (shop_ctx.mock?.live_shop ? LiveShopRepositoryJson : Li export class LiveShopService { static async getByHash(hash: string, fields?: LiveShopFields[]): Promise { try { - const result: LiveShop = await Repository().getByHash(hash, fields) + const result: LiveShop = await Repository().getOne({ filter: { hash } }, fields) + BroadcastService.emit('LiveShop', result) + + return result + } catch (error) { + throw new Error(error?.message) + } + } + static async getById(id: number, fields?: LiveShopFields[]): Promise { + try { + const result: LiveShop = await Repository().getOne({ filter: { id } }, fields) BroadcastService.emit('LiveShop', result) return result diff --git a/src/modules/live-shop/LiveShopTypes.ts b/src/modules/live-shop/LiveShopTypes.ts index e45939b..76cd6e3 100644 --- a/src/modules/live-shop/LiveShopTypes.ts +++ b/src/modules/live-shop/LiveShopTypes.ts @@ -43,7 +43,7 @@ export interface LiveShop { id: number hashRoom: string name: string - status: string + status: 'inLive' | 'finished' | 'warmup' | string urlLive: string title: string banner: LiveShopImage diff --git a/src/modules/live-shop/__test__/live-shop.test.ts b/src/modules/live-shop/__test__/live-shop.test.ts index c12e856..2e8b331 100644 --- a/src/modules/live-shop/__test__/live-shop.test.ts +++ b/src/modules/live-shop/__test__/live-shop.test.ts @@ -3,8 +3,14 @@ import { LiveShop } from '../LiveShopTypes' import { LiveShopService } from '../LiveShopService' const HASH_FILTER = 'abc123' +const ID_FILTER = 1 describe('Live Shop Module', () => { + it('Should get live shop by id with all fields successfully', async () => { + const liveShop: LiveShop = await LiveShopService.getById(ID_FILTER) + expect(liveShop.hashRoom).toEqual(HASH_FILTER) + }) + it('Should get live shop by hash with all fields successfully', async () => { const liveShop: LiveShop = await LiveShopService.getByHash(HASH_FILTER) expect(liveShop.hashRoom).toEqual(HASH_FILTER) From 6cf02b809b19242d97077db1f54bd67e20a21160 Mon Sep 17 00:00:00 2001 From: simaomeyrerdooca Date: Fri, 5 Jul 2024 15:41:00 -0300 Subject: [PATCH 04/14] refactor(live-shop): abstrai type --- src/modules/live-shop/LiveShopRepositoryGql.ts | 7 ++----- src/modules/live-shop/LiveShopTypes.ts | 5 +++++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/modules/live-shop/LiveShopRepositoryGql.ts b/src/modules/live-shop/LiveShopRepositoryGql.ts index ec813c7..4d68d69 100644 --- a/src/modules/live-shop/LiveShopRepositoryGql.ts +++ b/src/modules/live-shop/LiveShopRepositoryGql.ts @@ -1,12 +1,9 @@ import { getClient } from '../../services/GraphqlService' import { LiveShopQueries } from './LiveShopQueries' -import { LiveShop, LiveShopFields, LiveShopResponse } from './LiveShopTypes' +import { LiveShop, LiveShopFields, LiveShopFilter, LiveShopResponse } from './LiveShopTypes' export class LiveShopRepositoryGql { - static async getOne( - filter: { filter: { id?: number; hash?: string; slug?: string } }, - fields?: LiveShopFields[] - ): Promise { + static async getOne(filter: { filter: LiveShopFilter }, fields?: LiveShopFields[]): Promise { const liveShopQuery = new LiveShopQueries(fields) const fullQuery: string = liveShopQuery.getOneFullQuery() const { liveShop }: LiveShopResponse = await getClient().query(fullQuery, { ...filter }) diff --git a/src/modules/live-shop/LiveShopTypes.ts b/src/modules/live-shop/LiveShopTypes.ts index 76cd6e3..e067339 100644 --- a/src/modules/live-shop/LiveShopTypes.ts +++ b/src/modules/live-shop/LiveShopTypes.ts @@ -14,6 +14,11 @@ export type LiveShopFields = | 'createdAt' | 'updatedAt' +export interface LiveShopFilter { + id?: number + hash?: string + slug?: string +} export interface LiveShopImage { src: string alt: string From 62ceefc5523b23998e77b8f2b890195aae53996d Mon Sep 17 00:00:00 2001 From: simaomeyrerdooca Date: Fri, 5 Jul 2024 15:49:00 -0300 Subject: [PATCH 05/14] refactor: filter no json repo --- src/modules/live-shop/LiveShopRepositoryJson.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/live-shop/LiveShopRepositoryJson.ts b/src/modules/live-shop/LiveShopRepositoryJson.ts index c095d82..d592c5d 100644 --- a/src/modules/live-shop/LiveShopRepositoryJson.ts +++ b/src/modules/live-shop/LiveShopRepositoryJson.ts @@ -1,8 +1,8 @@ import liveShopJsonMock from '../../mocks/live-shop/live-shop.json' -import { LiveShop } from './LiveShopTypes' +import { LiveShop, LiveShopFilter } from './LiveShopTypes' export class LiveShopRepositoryJson { - static async getOne(filter: { id?: number; hash?: string; slug?: string }, fields?: string[]): Promise { + static async getOne({ filter }: { filter: LiveShopFilter }, fields?: string[]): Promise { const liveShop = liveShopJsonMock const liveShopResult = liveShop.find( item => From a15f92ab9d490364c89e385527f85d05d36a0072 Mon Sep 17 00:00:00 2001 From: simaomeyrerdooca Date: Thu, 3 Oct 2024 14:17:16 -0300 Subject: [PATCH 06/14] fix(live-shop): hasRoom filter --- src/mocks/live-shop/live-shop.json | 20 +++++++++++++++++-- .../live-shop/LiveShopRepositoryJson.ts | 2 +- src/modules/live-shop/LiveShopService.ts | 4 ++-- src/modules/live-shop/LiveShopTypes.ts | 3 ++- src/modules/product/ProductTypes.ts | 3 ++- 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/mocks/live-shop/live-shop.json b/src/mocks/live-shop/live-shop.json index 3a038ce..776b6b7 100644 --- a/src/mocks/live-shop/live-shop.json +++ b/src/mocks/live-shop/live-shop.json @@ -5,7 +5,7 @@ "name": "Super Live Shop", "slug": "super-live-shop", "status": "inLive", - "urlLive": "https://www.youtube.com/watch?v=J-K0cF0BCx4", + "urlLive": "https://www.youtube.com/watch?v=Tii6ljAdSm0", "title": "Bem vindo a Super Live Shop!", "banner": { "src": "https://picsum.photos/200", @@ -13,7 +13,23 @@ }, "products": [ { - "id": 101, + "id": 2915719, + "discount": { + "type": "markup", + "value": 10 + }, + "variations": [ + { + "id": 1001, + "discount": { + "type": "fixed", + "value": 5 + } + } + ] + }, + { + "id": 2915788, "discount": { "type": "markup", "value": 10 diff --git a/src/modules/live-shop/LiveShopRepositoryJson.ts b/src/modules/live-shop/LiveShopRepositoryJson.ts index d592c5d..5085d87 100644 --- a/src/modules/live-shop/LiveShopRepositoryJson.ts +++ b/src/modules/live-shop/LiveShopRepositoryJson.ts @@ -6,7 +6,7 @@ export class LiveShopRepositoryJson { const liveShop = liveShopJsonMock const liveShopResult = liveShop.find( item => - (filter.hash && item.hashRoom === filter.hash) || + (filter.hashRoom && item.hashRoom === filter.hashRoom) || (filter.id && item.id === filter.id) || (filter.slug && item.slug === filter.slug) ) diff --git a/src/modules/live-shop/LiveShopService.ts b/src/modules/live-shop/LiveShopService.ts index 7a977a1..fe24a48 100644 --- a/src/modules/live-shop/LiveShopService.ts +++ b/src/modules/live-shop/LiveShopService.ts @@ -6,9 +6,9 @@ import { LiveShop, LiveShopFields } from './LiveShopTypes' const Repository = () => (shop_ctx.mock?.live_shop ? LiveShopRepositoryJson : LiveShopRepositoryGql) export class LiveShopService { - static async getByHash(hash: string, fields?: LiveShopFields[]): Promise { + static async getByHash(hashRoom: string, fields?: LiveShopFields[]): Promise { try { - const result: LiveShop = await Repository().getOne({ filter: { hash } }, fields) + const result: LiveShop = await Repository().getOne({ filter: { hashRoom } }, fields) BroadcastService.emit('LiveShop', result) return result diff --git a/src/modules/live-shop/LiveShopTypes.ts b/src/modules/live-shop/LiveShopTypes.ts index e067339..d03d0ce 100644 --- a/src/modules/live-shop/LiveShopTypes.ts +++ b/src/modules/live-shop/LiveShopTypes.ts @@ -16,7 +16,7 @@ export type LiveShopFields = export interface LiveShopFilter { id?: number - hash?: string + hashRoom?: string slug?: string } export interface LiveShopImage { @@ -47,6 +47,7 @@ export interface LiveShopProduct { export interface LiveShop { id: number hashRoom: string + slug: string name: string status: 'inLive' | 'finished' | 'warmup' | string urlLive: string diff --git a/src/modules/product/ProductTypes.ts b/src/modules/product/ProductTypes.ts index ada8bfc..0009ef4 100644 --- a/src/modules/product/ProductTypes.ts +++ b/src/modules/product/ProductTypes.ts @@ -224,7 +224,7 @@ export interface Aggregator { } export interface OptionsGetProductList { filter: ProductPaginationFilter - fields?: ProductFields[] + fields?: Partial[] agg?: Aggregator } @@ -288,3 +288,4 @@ export type ProductFields = | 'variations' | 'components' | 'componentGroups' + | string From 57472e8b97188c53e46ff9319a12a2cd0d1d4ae6 Mon Sep 17 00:00:00 2001 From: simaomeyrerdooca Date: Wed, 9 Oct 2024 17:40:24 -0300 Subject: [PATCH 07/14] fix: corrige type e mock --- src/mocks/live-shop/live-shop.json | 8 ++++++-- src/modules/live-shop/LiveShopTypes.ts | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/mocks/live-shop/live-shop.json b/src/mocks/live-shop/live-shop.json index 776b6b7..e3743b6 100644 --- a/src/mocks/live-shop/live-shop.json +++ b/src/mocks/live-shop/live-shop.json @@ -13,7 +13,7 @@ }, "products": [ { - "id": 2915719, + "productId": 2915719, "discount": { "type": "markup", "value": 10 @@ -29,7 +29,7 @@ ] }, { - "id": 2915788, + "productId": 2915788, "discount": { "type": "markup", "value": 10 @@ -49,6 +49,10 @@ { "title": "Boas vindas!", "content": "Bem vindo a primeira live shop!" + }, + { + "title": "Os menores precos!", + "content": "Bem vindo que tá bombando!" } ], "alertVisible": true, diff --git a/src/modules/live-shop/LiveShopTypes.ts b/src/modules/live-shop/LiveShopTypes.ts index d03d0ce..3ad9ae5 100644 --- a/src/modules/live-shop/LiveShopTypes.ts +++ b/src/modules/live-shop/LiveShopTypes.ts @@ -39,7 +39,7 @@ export interface LiveShopVariation { discount: LiveShopDiscount } export interface LiveShopProduct { - id: number + productId: number discount: LiveShopDiscount variations: LiveShopVariation[] } From 0745db13df004b8c6a8d30dddedd2b6d8a21ea49 Mon Sep 17 00:00:00 2001 From: simaomeyrerdooca Date: Tue, 12 Nov 2024 15:08:54 -0300 Subject: [PATCH 08/14] fix: type --- src/modules/live-shop/LiveShopTypes.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/live-shop/LiveShopTypes.ts b/src/modules/live-shop/LiveShopTypes.ts index 3ad9ae5..a04d3d0 100644 --- a/src/modules/live-shop/LiveShopTypes.ts +++ b/src/modules/live-shop/LiveShopTypes.ts @@ -32,6 +32,7 @@ export interface LiveShopDiscount { export interface LiveShopMessage { title: string content: string + id?: string } export interface LiveShopVariation { From 1d8e6be81ed28163240cf10e4e6af766cf3b9133 Mon Sep 17 00:00:00 2001 From: simaomeyrerdooca Date: Tue, 12 Nov 2024 15:40:01 -0300 Subject: [PATCH 09/14] fix: remove mock --- src/modules/live-shop/LiveShopRepositoryJson.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/modules/live-shop/LiveShopRepositoryJson.ts b/src/modules/live-shop/LiveShopRepositoryJson.ts index 5085d87..f7a9472 100644 --- a/src/modules/live-shop/LiveShopRepositoryJson.ts +++ b/src/modules/live-shop/LiveShopRepositoryJson.ts @@ -1,9 +1,8 @@ -import liveShopJsonMock from '../../mocks/live-shop/live-shop.json' import { LiveShop, LiveShopFilter } from './LiveShopTypes' export class LiveShopRepositoryJson { static async getOne({ filter }: { filter: LiveShopFilter }, fields?: string[]): Promise { - const liveShop = liveShopJsonMock + const liveShop = shop_ctx.mock?.live_shop const liveShopResult = liveShop.find( item => (filter.hashRoom && item.hashRoom === filter.hashRoom) || From d52e643a652fe2d9f4dc58ce9baadc17771bdd0f Mon Sep 17 00:00:00 2001 From: simaomeyrerdooca Date: Wed, 4 Dec 2024 16:05:15 -0300 Subject: [PATCH 10/14] feat(LiveShop): add message id --- src/modules/live-shop/LiveShopQueries.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/live-shop/LiveShopQueries.ts b/src/modules/live-shop/LiveShopQueries.ts index 4703985..b8c1f0b 100644 --- a/src/modules/live-shop/LiveShopQueries.ts +++ b/src/modules/live-shop/LiveShopQueries.ts @@ -10,7 +10,7 @@ export class LiveShopQueries { } private getMessageFields() { - return '{title, content}' + return '{id, title, content}' } private getDiscountFields() { From ba166f31b3071e04a1574eb126cd49583c5b2598 Mon Sep 17 00:00:00 2001 From: simaomeyrerdooca Date: Wed, 4 Dec 2024 16:06:27 -0300 Subject: [PATCH 11/14] feat(LiveShop): add status --- src/modules/live-shop/LiveShopQueries.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/modules/live-shop/LiveShopQueries.ts b/src/modules/live-shop/LiveShopQueries.ts index b8c1f0b..fc445ef 100644 --- a/src/modules/live-shop/LiveShopQueries.ts +++ b/src/modules/live-shop/LiveShopQueries.ts @@ -10,7 +10,7 @@ export class LiveShopQueries { } private getMessageFields() { - return '{id, title, content}' + return '{id, title, content, status}' } private getDiscountFields() { @@ -30,7 +30,8 @@ export class LiveShopQueries { { productId, discount ${this.getDiscountFields()}, - variations ${this.getVariationFields()} + variations ${this.getVariationFields()}, + status }` } From 55d0ee8becfdacfef76af67d93e431b370df0848 Mon Sep 17 00:00:00 2001 From: simaomeyrerdooca Date: Wed, 4 Dec 2024 16:42:23 -0300 Subject: [PATCH 12/14] feat: add type LiveShopItemStatus --- src/modules/live-shop/LiveShopTypes.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/modules/live-shop/LiveShopTypes.ts b/src/modules/live-shop/LiveShopTypes.ts index a04d3d0..323b7bd 100644 --- a/src/modules/live-shop/LiveShopTypes.ts +++ b/src/modules/live-shop/LiveShopTypes.ts @@ -1,3 +1,5 @@ +export type LiveShopItemStatus = 'displaying' | 'hidden' | 'highlighting' + export type LiveShopFields = | 'id' | 'hashRoom' @@ -32,6 +34,7 @@ export interface LiveShopDiscount { export interface LiveShopMessage { title: string content: string + status: LiveShopItemStatus id?: string } @@ -43,6 +46,7 @@ export interface LiveShopProduct { productId: number discount: LiveShopDiscount variations: LiveShopVariation[] + status: LiveShopItemStatus } export interface LiveShop { From f309f7b2f7776168c252f94a641cefeceee21f85 Mon Sep 17 00:00:00 2001 From: simaomeyrerdooca Date: Tue, 17 Dec 2024 15:15:18 -0300 Subject: [PATCH 13/14] feat: remove omit --- src/modules/product/ProductTypes.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/product/ProductTypes.ts b/src/modules/product/ProductTypes.ts index 0009ef4..a0c0a4b 100644 --- a/src/modules/product/ProductTypes.ts +++ b/src/modules/product/ProductTypes.ts @@ -228,7 +228,7 @@ export interface OptionsGetProductList { agg?: Aggregator } -export interface ProductListFilter extends Omit { +export interface ProductListFilter extends ProductPaginationFilter { items?: number } From 9f45f1ec2d7e8989c4ff60c8bf6573acbf9105b9 Mon Sep 17 00:00:00 2001 From: simaomeyrerdooca Date: Mon, 10 Feb 2025 10:33:54 -0300 Subject: [PATCH 14/14] feat: add hashRoom --- src/modules/live-shop/LiveShopQueries.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/live-shop/LiveShopQueries.ts b/src/modules/live-shop/LiveShopQueries.ts index fc445ef..5fc6fe8 100644 --- a/src/modules/live-shop/LiveShopQueries.ts +++ b/src/modules/live-shop/LiveShopQueries.ts @@ -39,6 +39,7 @@ export class LiveShopQueries { return [ 'id', 'name', + 'hashRoom', 'status', 'urlLive', 'title',