54 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
			
		
		
	
	
			54 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
import path from 'path';
 | 
						|
import { GrayApiBid } from '../models/grays.com/grays-api-bid.js';
 | 
						|
import { GraysProductBid } from '../models/grays.com/grays-product-bid.js';
 | 
						|
import configs from '../system/config.js';
 | 
						|
import CONSTANTS from '../system/constants.js';
 | 
						|
import { sanitizeFileName } from '../system/utils.js';
 | 
						|
import * as fs from 'fs';
 | 
						|
import _ from 'lodash';
 | 
						|
 | 
						|
const ONE_MINUTE = 60 * 1000;
 | 
						|
 | 
						|
export const handleCloseRemoveProduct = (data) => {
 | 
						|
    if (!Array.isArray(data)) return;
 | 
						|
 | 
						|
    data.forEach(async (item) => {
 | 
						|
        if (item.page_context) {
 | 
						|
            safeClosePage(item);
 | 
						|
        }
 | 
						|
    });
 | 
						|
};
 | 
						|
 | 
						|
export const createBidProduct = (web, data) => {
 | 
						|
    switch (web.origin_url) {
 | 
						|
        case configs.WEB_URLS.GRAYS: {
 | 
						|
            return new GraysProductBid({ ...data });
 | 
						|
        }
 | 
						|
    }
 | 
						|
};
 | 
						|
 | 
						|
export const createApiBid = (web) => {
 | 
						|
    switch (web.origin_url) {
 | 
						|
        case configs.WEB_URLS.GRAYS: {
 | 
						|
            return new GrayApiBid({ ...web });
 | 
						|
        }
 | 
						|
    }
 | 
						|
};
 | 
						|
 | 
						|
export const deleteProfile = (data) => {
 | 
						|
    const filePath = path.join(CONSTANTS.PROFILE_PATH, sanitizeFileName(data.origin_url) + '.json');
 | 
						|
 | 
						|
    if (fs.existsSync(filePath)) {
 | 
						|
        fs.unlinkSync(filePath);
 | 
						|
        return true;
 | 
						|
    }
 | 
						|
 | 
						|
    return false;
 | 
						|
};
 | 
						|
 | 
						|
export const shouldUpdateProductTab = (productTab) => {
 | 
						|
    const updatedAt = new Date(productTab.updated_at).getTime();
 | 
						|
    const now = Date.now();
 | 
						|
    return now - updatedAt >= ONE_MINUTE;
 | 
						|
};
 |