API设计

创建关系

POST /models/{modelId}/relation

{
  "type": "manyToMany",
  "description": [{}],
  "relationTableName": "workIndustries",
  "extraFields": [
    {
      "fieldName": "year",
      "esType": "text",
      "pgType": "text"
    }
  ]
}

读取Model详情

GET /models/{modelId}

{
  //...

  relationFields: [
                    {
                        fieldName: 'experiences',
                        type: 'oneToMany',
                        contentModelId: 2,
                        mainField: 'title',
                        contentModelAlias: 'experiences'
                        },
                            'talentId',
                        aliases: [
                            { contentModelId: 6, mainField: 'zzz', contentModelAlias: 'xxxx' },
                            { contentModelId: 7, mainField: 'zzz', contentModelAlias: 'xxx' }
                        ]
                    },
                    {
                        fieldName: 'workIndustries',
                        type: 'manyToMany',
                        alias: { contentModelId: 4, mainField: 'name', alias: 'workIndustries' },
                        foreignKey: 'companyId',
            extraFields:[{
              "fieldName": "year",
              "esType": "text",
              "pgType": "text"
            }]
                    },
                    {
                        fieldName: 'address',
                        type: 'oneToOne',
                        alias: { contentModelId: 5, mainField: 'city', alias: 'address' },
                        foreignKey: 'companyId'
                    }
                ];
}

查询数据

GET /models/{modelId}/data

{
  "id":1,
  "fullName":"zhangmilai",
  "workIndustries": [
            {
                "id": 4,
                "name": "Drug Retail",
                "level": 1,
                "parentId": 0,
                "createdAt": "2019-12-08T21:26:37.727Z",
                "updatedAt": "2019-12-08T21:26:37.727Z",
                "years": 4
            },
            {
                "id": 3,
                "name": "Casinos & Gaming",
                "level": 1,
                "parentId": 0,
                "createdAt": "2019-12-08T21:26:37.727Z",
                "updatedAt": "2019-12-08T21:26:37.727Z",
                "years": 9
            }
        ],
}

新增/编辑数据

PUT /models/{modelId}/data/1

{

  "fullName":"zhangmilai",
  "workIndustries": [
            {
                "id": 4,
                "years": 4
            },
            {
                "id": 3,
                "years": 9
            }
        ],
}

业务逻辑变更

创建关系

model.relation.create.dto.ts

+++++++++++++++++++++
  @IsJSON()
  public extraFields!: JSON;
+++++++++++++++++++++

model.relation.service.ts

  • createModelRelation()

db.structure.service.ts

  • buildManyToMany()

CURD - Create

model.data.service.ts

  • beforeQuery()
    middle: relation.tableName 
    ->  
    middle:{
      tableName,
      extraFields 
    }
    
    db.curd.service.ts

CURD - Update

ES(略)

results matching ""

    No results matching ""