| 
									
										
										
										
											2019-05-06 15:33:25 +02:00
										 |  |  | const waitRestart = require('./waitRestart'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = ({ rq }) => { | 
					
						
							| 
									
										
										
										
											2019-10-22 18:01:03 +02:00
										 |  |  |   async function createComponent(data) { | 
					
						
							| 
									
										
										
										
											2019-08-08 11:59:45 +02:00
										 |  |  |     await rq({ | 
					
						
							| 
									
										
										
										
											2019-10-22 18:01:03 +02:00
										 |  |  |       url: '/content-type-builder/components', | 
					
						
							| 
									
										
										
										
											2019-08-08 11:59:45 +02:00
										 |  |  |       method: 'POST', | 
					
						
							|  |  |  |       body: { | 
					
						
							| 
									
										
										
										
											2019-11-14 16:37:57 +01:00
										 |  |  |         component: { | 
					
						
							|  |  |  |           category: 'default', | 
					
						
							|  |  |  |           icon: 'default', | 
					
						
							|  |  |  |           connection: 'default', | 
					
						
							|  |  |  |           ...data, | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2019-08-08 11:59:45 +02:00
										 |  |  |       }, | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     await waitRestart(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-22 18:01:03 +02:00
										 |  |  |   async function deleteComponent(name) { | 
					
						
							| 
									
										
										
										
											2019-08-08 11:59:45 +02:00
										 |  |  |     await rq({ | 
					
						
							| 
									
										
										
										
											2019-10-22 18:01:03 +02:00
										 |  |  |       url: `/content-type-builder/components/${name}`, | 
					
						
							| 
									
										
										
										
											2019-08-08 11:59:45 +02:00
										 |  |  |       method: 'DELETE', | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     await waitRestart(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-12 10:15:25 +01:00
										 |  |  |   function createContentTypeWithType(name, type, opts = {}) { | 
					
						
							|  |  |  |     return createContentType({ | 
					
						
							| 
									
										
										
										
											2019-08-08 10:41:05 +02:00
										 |  |  |       connection: 'default', | 
					
						
							|  |  |  |       name, | 
					
						
							| 
									
										
										
										
											2019-11-14 16:37:57 +01:00
										 |  |  |       attributes: { | 
					
						
							|  |  |  |         field: { | 
					
						
							|  |  |  |           type, | 
					
						
							|  |  |  |           ...opts, | 
					
						
							| 
									
										
										
										
											2019-08-08 10:41:05 +02:00
										 |  |  |         }, | 
					
						
							| 
									
										
										
										
											2019-11-14 16:37:57 +01:00
										 |  |  |       }, | 
					
						
							| 
									
										
										
										
											2019-08-08 10:41:05 +02:00
										 |  |  |     }); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-12 10:15:25 +01:00
										 |  |  |   async function createContentType(data) { | 
					
						
							| 
									
										
										
										
											2019-05-06 15:33:25 +02:00
										 |  |  |     await rq({ | 
					
						
							| 
									
										
										
										
											2019-11-14 16:37:57 +01:00
										 |  |  |       url: '/content-type-builder/content-types', | 
					
						
							| 
									
										
										
										
											2019-05-06 15:33:25 +02:00
										 |  |  |       method: 'POST', | 
					
						
							| 
									
										
										
										
											2019-08-08 11:59:45 +02:00
										 |  |  |       body: { | 
					
						
							| 
									
										
										
										
											2019-11-14 16:37:57 +01:00
										 |  |  |         contentType: { | 
					
						
							|  |  |  |           connection: 'default', | 
					
						
							|  |  |  |           ...data, | 
					
						
							|  |  |  |         }, | 
					
						
							| 
									
										
										
										
											2019-08-08 11:59:45 +02:00
										 |  |  |       }, | 
					
						
							| 
									
										
										
										
											2019-05-06 15:33:25 +02:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     await waitRestart(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-12 10:15:25 +01:00
										 |  |  |   async function createContentTypes(models) { | 
					
						
							| 
									
										
										
										
											2019-05-06 15:33:25 +02:00
										 |  |  |     for (let model of models) { | 
					
						
							| 
									
										
										
										
											2019-12-12 10:15:25 +01:00
										 |  |  |       await createContentType(model); | 
					
						
							| 
									
										
										
										
											2019-05-06 15:33:25 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-12 10:15:25 +01:00
										 |  |  |   async function deleteContentType(model) { | 
					
						
							| 
									
										
										
										
											2019-05-06 15:33:25 +02:00
										 |  |  |     await rq({ | 
					
						
							| 
									
										
										
										
											2019-11-14 16:37:57 +01:00
										 |  |  |       url: `/content-type-builder/content-types/application::${model}.${model}`, | 
					
						
							| 
									
										
										
										
											2019-05-06 15:33:25 +02:00
										 |  |  |       method: 'DELETE', | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     await waitRestart(); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-12 10:15:25 +01:00
										 |  |  |   async function deleteContentTypes(models) { | 
					
						
							| 
									
										
										
										
											2019-05-06 15:33:25 +02:00
										 |  |  |     for (let model of models) { | 
					
						
							| 
									
										
										
										
											2019-12-12 10:15:25 +01:00
										 |  |  |       await deleteContentType(model); | 
					
						
							| 
									
										
										
										
											2019-05-06 15:33:25 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return { | 
					
						
							| 
									
										
										
										
											2019-10-22 18:01:03 +02:00
										 |  |  |     createComponent, | 
					
						
							|  |  |  |     deleteComponent, | 
					
						
							| 
									
										
										
										
											2019-08-08 11:59:45 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-12 10:15:25 +01:00
										 |  |  |     createContentType, | 
					
						
							|  |  |  |     createContentTypes, | 
					
						
							|  |  |  |     createContentTypeWithType, | 
					
						
							|  |  |  |     deleteContentType, | 
					
						
							|  |  |  |     deleteContentTypes, | 
					
						
							| 
									
										
										
										
											2019-05-06 15:33:25 +02:00
										 |  |  |   }; | 
					
						
							|  |  |  | }; |