mirror of
				https://github.com/strapi/strapi.git
				synced 2025-11-03 19:36:20 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			42 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			42 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
'use strict';
 | 
						|
 | 
						|
const { getService } = require('../utils');
 | 
						|
const {
 | 
						|
  validateGenerateUIDInput,
 | 
						|
  validateCheckUIDAvailabilityInput,
 | 
						|
  validateUIDField,
 | 
						|
} = require('./validation');
 | 
						|
 | 
						|
module.exports = {
 | 
						|
  async generateUID(ctx) {
 | 
						|
    const { contentTypeUID, field, data } = await validateGenerateUIDInput(ctx.request.body);
 | 
						|
 | 
						|
    await validateUIDField(contentTypeUID, field);
 | 
						|
 | 
						|
    const uidService = getService('uid');
 | 
						|
 | 
						|
    ctx.body = {
 | 
						|
      data: await uidService.generateUIDField({ contentTypeUID, field, data }),
 | 
						|
    };
 | 
						|
  },
 | 
						|
 | 
						|
  async checkUIDAvailability(ctx) {
 | 
						|
    const { contentTypeUID, field, value } = await validateCheckUIDAvailabilityInput(
 | 
						|
      ctx.request.body
 | 
						|
    );
 | 
						|
 | 
						|
    await validateUIDField(contentTypeUID, field);
 | 
						|
 | 
						|
    const uidService = getService('uid');
 | 
						|
 | 
						|
    const isAvailable = await uidService.checkUIDAvailability({ contentTypeUID, field, value });
 | 
						|
 | 
						|
    ctx.body = {
 | 
						|
      isAvailable,
 | 
						|
      suggestion: !isAvailable
 | 
						|
        ? await uidService.findUniqueUID({ contentTypeUID, field, value })
 | 
						|
        : null,
 | 
						|
    };
 | 
						|
  },
 | 
						|
};
 |