Skip to content

Commit

Permalink
Merge pull request #477 from teambition/feat/customfieldcategory-schema
Browse files Browse the repository at this point in the history
feat(schema): 添加 CustomFieldCategorySchema,并修复 CustomFieldLink 相关定义
  • Loading branch information
chuan6 committed Jun 6, 2018
2 parents 12d8c2d + 270a0f6 commit 2c50839
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 6 deletions.
11 changes: 8 additions & 3 deletions src/apis/customfieldlink/get.ts
Expand Up @@ -11,8 +11,8 @@ export function getCustomFieldLinksFetch(
this: SDKFetch,
projectId: ProjectId,
boundType: CustomFieldBoundType
): Observable<CustomFieldLinkSchema> {
return this.get<CustomFieldLinkSchema>(
): Observable<CustomFieldLinkSchema[]> {
return this.get<CustomFieldLinkSchema[]>(
`projects/${projectId}/customfieldlinks`,
{ boundType }
)
Expand All @@ -35,7 +35,12 @@ export function getCustomFieldLinks(
cacheValidate: CacheStrategy.Request,
tableName: 'CustomFieldLink',
request: this.fetch.getCustomFieldLinks(projectId, boundType),
query: { where: [{ _projectId: projectId }] }
query: {
where: { _projectId: projectId, boundType: boundType },
orderBy: [
{ fieldName: 'pos', orderBy: 'ASC' }
],
}
})
}

Expand Down
10 changes: 9 additions & 1 deletion src/schemas/CustomField.ts
@@ -1,6 +1,6 @@
import { SchemaDef, RDBType } from 'reactivedb/interface'
import { schemaColl } from './schemas'
import { CustomFieldType, CustomFieldBoundType } from 'teambition-types'
import { CustomFieldType, CustomFieldBoundType, CustomFieldCategoryId } from 'teambition-types'
import { CustomFieldId, OrganizationId, ProjectId, RoleId, UserId } from 'teambition-types'

import { CustomFieldChoiceSchema } from './CustomFieldChoice'
Expand All @@ -12,8 +12,10 @@ export interface CustomFieldSchema {
_projectId?: ProjectId
_roleIds: RoleId[]
boundType: CustomFieldBoundType
categoryIds: CustomFieldCategoryId[]
choices: CustomFieldChoiceSchema[]
created: string
description: string
displayed: boolean
name: string
pos: number
Expand Down Expand Up @@ -41,12 +43,18 @@ const schema: SchemaDef<CustomFieldSchema> = {
boundType: {
type: RDBType.STRING
},
categoryIds: {
type: RDBType.LITERAL_ARRAY
},
choices: {
type: RDBType.OBJECT
},
created: {
type: RDBType.DATE_TIME
},
description: {
type: RDBType.STRING
},
displayed: {
type: RDBType.BOOLEAN
},
Expand Down
40 changes: 40 additions & 0 deletions src/schemas/CustomFieldCategory.ts
@@ -0,0 +1,40 @@
import { RDBType, SchemaDef } from 'reactivedb/interface'
import { CustomFieldCategoryId, UserId, OrganizationId } from 'teambition-types'
import { schemaColl } from './schemas'

export interface CustomFieldCategorySchema {
_id: CustomFieldCategoryId
_creatorId: UserId
_organizationId: OrganizationId
created: string
isDeleted: boolean
name: string
updated: string
}

const schema: SchemaDef<CustomFieldCategorySchema> = {
_id: {
type: RDBType.STRING,
primaryKey: true,
},
_creatorId: {
type: RDBType.STRING
},
_organizationId: {
type: RDBType.STRING
},
created: {
type: RDBType.DATE_TIME
},
isDeleted: {
type: RDBType.BOOLEAN
},
name: {
type: RDBType.STRING
},
updated: {
type: RDBType.DATE_TIME
}
}

schemaColl.add({ name: 'CustomFieldCategory', schema })
8 changes: 6 additions & 2 deletions src/schemas/CustomFieldLink.ts
@@ -1,6 +1,6 @@
import { SchemaDef, RDBType } from 'reactivedb/interface'
import { schemaColl } from './schemas'
import { CustomFieldType } from 'teambition-types'
import { CustomFieldType, CustomFieldBoundType } from 'teambition-types'
import { CustomFieldId, CustomFieldLinkId, ProjectId, RoleId } from 'teambition-types'

import { CustomFieldChoiceSchema } from './CustomFieldChoice'
Expand All @@ -10,6 +10,7 @@ export interface CustomFieldLinkSchema {
_id: CustomFieldLinkId
_projectId: ProjectId
_roleIds: RoleId[]
boundType: CustomFieldBoundType
choices: CustomFieldChoiceSchema[]
displayed: boolean
name: string
Expand All @@ -31,6 +32,9 @@ const schema: SchemaDef<CustomFieldLinkSchema> = {
_roleIds: {
type: RDBType.LITERAL_ARRAY
},
boundType: {
type: RDBType.STRING
},
choices: {
type: RDBType.OBJECT
},
Expand All @@ -45,7 +49,7 @@ const schema: SchemaDef<CustomFieldLinkSchema> = {
},
type: {
type: RDBType.STRING
},
}
}

schemaColl.add({ schema, name: 'CustomFieldLink' })
2 changes: 2 additions & 0 deletions src/schemas/index.ts
Expand Up @@ -61,6 +61,8 @@ import './Tag'
export * from './Tag'
import './CustomField'
export * from './CustomField'
import './CustomFieldCategory'
export * from './CustomFieldCategory'
// import './CustomFieldChoice' // 目前不需建表
export * from './CustomFieldChoice'
import './CustomFieldLink'
Expand Down
1 change: 1 addition & 0 deletions src/sockets/TableAlias.ts
Expand Up @@ -16,6 +16,7 @@ export default {
Activities: 'Activity',
HomeActivities: 'Activity',
TaskflowStatus: 'TaskflowStatus', // 会被作为复数形式去除最后的s
CustomFieldCategories: 'CustomFieldCategory'
}
// 如添加条目,请配合相关项目调试,并在
// test/sockets/mapToTable.spec.ts 添加相应测试。
1 change: 1 addition & 0 deletions src/teambition.ts
Expand Up @@ -5,6 +5,7 @@ declare module 'teambition-types' {
export interface ActivityId extends String { kind?: 'ActivityId' }
export interface ApplicationId extends String { kind?: 'ApplicationId' }
export interface CollectionId extends String { kind?: 'CollectionId' }
export interface CustomFieldCategoryId extends String { kind?: 'CustomFieldCategoryId' }
export interface CustomFieldChoiceId extends String { kind?: 'CustomFieldChoiceId' }
export interface CustomFieldId extends String { kind?: 'CustomFieldId' }
export interface CustomFieldLinkId extends String { kind?: 'CustomFieldLinkId' }
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/customfieldlinks.fixture.ts
@@ -1,4 +1,5 @@
export const customFieldLink = {
boundType: 'application',
pos: 65536,
_roleIds: [],
_projectId: '5a977492a4e7b30012b6436b',
Expand Down
8 changes: 8 additions & 0 deletions test/sockets/mapToTable.spec.ts
Expand Up @@ -115,4 +115,12 @@ describe('TableInfoByMessageType + schemas + TableAlias spec', () => {
})
})

it('should map `CustomFieldCategories`(case-insensitive) to `CustomFieldCategory`', () => {
['CustomFieldCategories', 'customfieldcategories'].forEach((msgType) => {
expect(mapToTable.getTableInfo(msgType)).to.deep.equal({
pkName: '_id', tabName: 'CustomFieldCategory'
})
})
})

})

0 comments on commit 2c50839

Please sign in to comment.