Skip to content

Commit

Permalink
fix(platform-server): make timer field concrete types
Browse files Browse the repository at this point in the history
  • Loading branch information
lizimeow committed Sep 15, 2022
1 parent 4b26e22 commit 34339e5
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/platform-server/src/db/mysql/runner.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ registerEnumType(JobType, {
description: 'available job types',
})

@ObjectType({ description: 'runner register tokens and infomations' })
@ObjectType({ description: 'runner register tokens and information' })
@Entity()
export class Runner extends BaseEntity {
@PrimaryGeneratedColumn('increment')
Expand Down
9 changes: 4 additions & 5 deletions packages/platform-server/src/db/mysql/timer.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ limitations under the License.
*/

import { ObjectType, Field, Int, GraphQLISODateTime, registerEnumType } from '@nestjs/graphql'
import GraphQLJSON from 'graphql-type-json'
import { Column, Entity, PrimaryGeneratedColumn, BaseEntity, RelationId, OneToOne, JoinColumn, Index } from 'typeorm'

import type { Project } from './project.entity'
Expand Down Expand Up @@ -63,19 +62,19 @@ export class Timer extends BaseEntity {
@Column({ type: 'tinyint', nullable: true })
timeOfDay!: number | null

@Field(() => GraphQLISODateTime, { description: 'next evaluation time of this schedule task' })
@Field(() => GraphQLISODateTime, { nullable: true, description: 'next evaluation time of this schedule task' })
@Column({ type: 'timestamp' })
nextTriggerTime!: Date

@Field(() => GraphQLJSON, { description: 'related page ids' })
@Field(() => [Int], { description: 'related page ids' })
@Column('text', { transformer: dbJSONTransformerFactory([]), nullable: true })
pageIds!: number[]

@Field(() => GraphQLJSON, { description: 'related profile ids' })
@Field(() => [Int], { description: 'related profile ids' })
@Column('text', { transformer: dbJSONTransformerFactory([]), nullable: true })
profileIds!: number[]

@Field(() => GraphQLJSON, { description: 'related environment ids' })
@Field(() => [Int], { description: 'related environment ids' })
@Column('text', { transformer: dbJSONTransformerFactory([]), nullable: true })
envIds!: number[]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ test.serial('get pages with property', async (t) => {
const payload1 = await service.getPageWithProperty(1)
const payload2 = await service.getPageWithProperty(1, [pages[3].iid])
const payload3 = await service.getPageWithProperty(1, undefined, [profiles[1].iid], [envs[1].iid])
const payload4 = await service.getPageWithProperty(1, [pages[1].iid], [profiles[1].iid], [envs[1].iid])

t.is(payload1.pages.length, 3)
t.is(payload1.propertyIds.length, 5)
Expand All @@ -67,7 +68,10 @@ test.serial('get pages with property', async (t) => {
t.is(payload2.propertyIds.length, 0)

t.is(payload3.pages.length, 3)
t.is(payload3.propertyIds.length, 3)
t.is(payload3.propertyIds.length, 2)

t.is(payload4.pages.length, 1)
t.is(payload4.propertyIds.length, 1)
})

test.serial('get pages with property when page is disabled', async (t) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/platform-server/src/modules/page/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@ export class PageService {

const propertyIds: PagePropertySchema[] = []

// user specifies envs and profiles
// user specifies pages and envs and profiles
// so we will just ignore the predefined Page x Env x Profile bindings
if (envIids?.length && profileIids?.length) {
if (pageIids?.length && envIids?.length && profileIids?.length) {
pages.forEach((page) => {
envs.forEach((env) => {
if (!validEnvIdSet.has(env.id)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export function SettingsSchedule() {
(typeof hour === 'number' && (hour > 168 || hour < 1))
) {
notify.error({
content: 'Failed to save.',
content: 'You should specify something.',
duration: 3000,
})
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ export const defaultTimer = {
schedule: ScheduleType.Off,
hour: null,
timeOfDay: null,
nextTriggerTime: null,
monitorType: ScheduleMonitorType.All,
pageIds: [],
envIds: [],
profileIds: [],
} as TimerSchema
}

@Module('ScheduleModule')
export class ScheduleModule extends EffectModule<State> {
Expand Down
16 changes: 8 additions & 8 deletions packages/schema/src/server-schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -601,16 +601,16 @@ type Timer {
timeOfDay: Int

"""next evaluation time of this schedule task"""
nextTriggerTime: DateTime!
nextTriggerTime: DateTime

"""related page ids"""
pageIds: JSON!
pageIds: [Int!]!

"""related profile ids"""
profileIds: JSON!
profileIds: [Int!]!

"""related environment ids"""
envIds: JSON!
envIds: [Int!]!

"""
whether only specific pages/profiles/envs will be measured when task triggered
Expand Down Expand Up @@ -702,7 +702,7 @@ type AppVersion {
createdAt: DateTime!
}

"""runner register tokens and infomations"""
"""runner register tokens and information"""
type Runner {
id: ID!
name: String!
Expand Down Expand Up @@ -1356,13 +1356,13 @@ input UpdateTimerInput {
timeOfDay: Int

"""related page ids"""
pageIds: JSON
pageIds: [Int!]

"""related profile ids"""
profileIds: JSON
profileIds: [Int!]

"""related environment ids"""
envIds: JSON
envIds: [Int!]

"""
whether only specific pages/profiles/envs will be measured when task triggered
Expand Down

0 comments on commit 34339e5

Please sign in to comment.