diff --git a/src/apis/customfieldlink/get.ts b/src/apis/customfieldlink/get.ts index 8f9e295cd..0db51675e 100644 --- a/src/apis/customfieldlink/get.ts +++ b/src/apis/customfieldlink/get.ts @@ -11,8 +11,8 @@ export function getCustomFieldLinksFetch( this: SDKFetch, projectId: ProjectId, boundType: CustomFieldBoundType -): Observable { - return this.get( +): Observable { + return this.get( `projects/${projectId}/customfieldlinks`, { boundType } ) @@ -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' } + ], + } }) } diff --git a/src/schemas/CustomField.ts b/src/schemas/CustomField.ts index 97d4b0278..706f67ffe 100644 --- a/src/schemas/CustomField.ts +++ b/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' @@ -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 @@ -41,12 +43,18 @@ const schema: SchemaDef = { 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 }, diff --git a/src/schemas/CustomFieldCategory.ts b/src/schemas/CustomFieldCategory.ts new file mode 100644 index 000000000..f3cee6d09 --- /dev/null +++ b/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 = { + _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 }) diff --git a/src/schemas/CustomFieldLink.ts b/src/schemas/CustomFieldLink.ts index 7627ce9a9..3570d661a 100644 --- a/src/schemas/CustomFieldLink.ts +++ b/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' @@ -10,6 +10,7 @@ export interface CustomFieldLinkSchema { _id: CustomFieldLinkId _projectId: ProjectId _roleIds: RoleId[] + boundType: CustomFieldBoundType choices: CustomFieldChoiceSchema[] displayed: boolean name: string @@ -31,6 +32,9 @@ const schema: SchemaDef = { _roleIds: { type: RDBType.LITERAL_ARRAY }, + boundType: { + type: RDBType.STRING + }, choices: { type: RDBType.OBJECT }, @@ -45,7 +49,7 @@ const schema: SchemaDef = { }, type: { type: RDBType.STRING - }, + } } schemaColl.add({ schema, name: 'CustomFieldLink' }) diff --git a/src/schemas/index.ts b/src/schemas/index.ts index c6dabb087..7b8217be9 100644 --- a/src/schemas/index.ts +++ b/src/schemas/index.ts @@ -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' diff --git a/src/sockets/TableAlias.ts b/src/sockets/TableAlias.ts index a31e0484a..34ac9ad11 100644 --- a/src/sockets/TableAlias.ts +++ b/src/sockets/TableAlias.ts @@ -16,6 +16,7 @@ export default { Activities: 'Activity', HomeActivities: 'Activity', TaskflowStatus: 'TaskflowStatus', // 会被作为复数形式去除最后的s + CustomFieldCategories: 'CustomFieldCategory' } // 如添加条目,请配合相关项目调试,并在 // test/sockets/mapToTable.spec.ts 添加相应测试。 diff --git a/src/teambition.ts b/src/teambition.ts index 0de8d972d..67fd26b62 100644 --- a/src/teambition.ts +++ b/src/teambition.ts @@ -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' } diff --git a/test/fixtures/customfieldlinks.fixture.ts b/test/fixtures/customfieldlinks.fixture.ts index 962fbfa8e..b92a3dfd5 100644 --- a/test/fixtures/customfieldlinks.fixture.ts +++ b/test/fixtures/customfieldlinks.fixture.ts @@ -1,4 +1,5 @@ export const customFieldLink = { + boundType: 'application', pos: 65536, _roleIds: [], _projectId: '5a977492a4e7b30012b6436b', diff --git a/test/sockets/mapToTable.spec.ts b/test/sockets/mapToTable.spec.ts index 70f76c672..9252be31b 100644 --- a/test/sockets/mapToTable.spec.ts +++ b/test/sockets/mapToTable.spec.ts @@ -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' + }) + }) + }) + })