Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: refactor segments to stop depending on the implementation (#3315)
## About the changes - Introducing ISegmentService interface to decouple from the actual implementation - Moving UpsertSegmentSchema to OSS to be able to use types - Added comments where our code is coupled with segments just to highlight and have a conversation about some use cases if needed, but they can be removed before merging - Removed segment service from some project features as it was not used
- Loading branch information
1 parent
69a11ba
commit 1d0bc83
Showing
21 changed files
with
132 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { FromSchema } from 'json-schema-to-ts'; | ||
import { constraintSchema } from './constraint-schema'; | ||
|
||
export const upsertSegmentSchema = { | ||
$id: '#/components/schemas/upsertSegmentSchema', | ||
type: 'object', | ||
required: ['name', 'constraints'], | ||
properties: { | ||
name: { | ||
type: 'string', | ||
}, | ||
description: { | ||
type: 'string', | ||
nullable: true, | ||
}, | ||
project: { | ||
type: 'string', | ||
nullable: true, | ||
}, | ||
constraints: { | ||
type: 'array', | ||
items: { | ||
$ref: '#/components/schemas/constraintSchema', | ||
}, | ||
}, | ||
}, | ||
components: { | ||
schemas: { | ||
constraintSchema, | ||
}, | ||
}, | ||
} as const; | ||
|
||
export type UpsertSegmentSchema = FromSchema<typeof upsertSegmentSchema>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { UpsertSegmentSchema } from 'lib/openapi'; | ||
import { ISegment, IUser } from 'lib/types'; | ||
|
||
export interface ISegmentService { | ||
updateStrategySegments: ( | ||
strategyId: string, | ||
segmentIds: number[], | ||
) => Promise<void>; | ||
|
||
addToStrategy(id: number, strategyId: string): Promise<void>; | ||
|
||
getByStrategy(strategyId: string): Promise<ISegment[]>; | ||
|
||
getActive(): Promise<ISegment[]>; | ||
|
||
getAll(): Promise<ISegment[]>; | ||
|
||
create( | ||
data: UpsertSegmentSchema, | ||
user: Partial<Pick<IUser, 'username' | 'email'>>, | ||
): Promise<ISegment>; | ||
|
||
delete(id: number, user: IUser): Promise<void>; | ||
|
||
cloneStrategySegments( | ||
sourceStrategyId: string, | ||
targetStrategyId: string, | ||
): Promise<void>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.