Deploy to production #56
			
				
			
		
		
		
	| 
						 | 
				
			
			@ -16,7 +16,10 @@ export const createScrapConfig = async (
 | 
			
		|||
      url: "scrap-configs",
 | 
			
		||||
      withCredentials: true,
 | 
			
		||||
      method: "POST",
 | 
			
		||||
      data: newData,
 | 
			
		||||
      data: {
 | 
			
		||||
        ...newData,
 | 
			
		||||
        enable: newData.enable === "1",
 | 
			
		||||
      },
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    handleSuccess(data);
 | 
			
		||||
| 
						 | 
				
			
			@ -28,14 +31,14 @@ export const createScrapConfig = async (
 | 
			
		|||
};
 | 
			
		||||
 | 
			
		||||
export const updateScrapConfig = async (scrapConfig: Partial<IScrapConfig>) => {
 | 
			
		||||
  const { search_url, keywords, id } = removeFalsyValues(scrapConfig);
 | 
			
		||||
  const { search_url, keywords, id, enable } = removeFalsyValues(scrapConfig);
 | 
			
		||||
 | 
			
		||||
  try {
 | 
			
		||||
    const { data } = await axios({
 | 
			
		||||
      url: "scrap-configs/" + id,
 | 
			
		||||
      withCredentials: true,
 | 
			
		||||
      method: "PUT",
 | 
			
		||||
      data: { search_url, keywords },
 | 
			
		||||
      data: { search_url, keywords, enable: enable === "1" },
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    handleSuccess(data);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,6 +4,7 @@ import {
 | 
			
		|||
  LoadingOverlay,
 | 
			
		||||
  Modal,
 | 
			
		||||
  ModalProps,
 | 
			
		||||
  Select,
 | 
			
		||||
  Textarea,
 | 
			
		||||
  TextInput,
 | 
			
		||||
} from "@mantine/core";
 | 
			
		||||
| 
						 | 
				
			
			@ -28,6 +29,7 @@ const schema = z.object({
 | 
			
		|||
    .string({ message: "Keyword is required" })
 | 
			
		||||
    .min(1, { message: "Keyword is required" })
 | 
			
		||||
    .optional(),
 | 
			
		||||
  enable: z.enum(["1", "0"], { required_error: "Enable is required" }),
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
export default function ScrapConfigModal({
 | 
			
		||||
| 
						 | 
				
			
			@ -93,9 +95,18 @@ export default function ScrapConfigModal({
 | 
			
		|||
    form.reset();
 | 
			
		||||
    if (!data) return;
 | 
			
		||||
 | 
			
		||||
    form.setValues(data.scrap_config);
 | 
			
		||||
    const values = {
 | 
			
		||||
      ...data.scrap_config,
 | 
			
		||||
      enable: (data.scrap_config?.enable === undefined
 | 
			
		||||
        ? "1"
 | 
			
		||||
        : data.scrap_config.enable
 | 
			
		||||
        ? "1"
 | 
			
		||||
        : "0") as "0" | "1",
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    prevData.current = data.scrap_config;
 | 
			
		||||
    form.setValues(values);
 | 
			
		||||
 | 
			
		||||
    prevData.current = values;
 | 
			
		||||
    // eslint-disable-next-line react-hooks/exhaustive-deps
 | 
			
		||||
  }, [data]);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -121,6 +132,23 @@ export default function ScrapConfigModal({
 | 
			
		|||
        onSubmit={form.onSubmit(handleSubmit)}
 | 
			
		||||
        className="grid grid-cols-2 gap-2.5"
 | 
			
		||||
      >
 | 
			
		||||
        <Select
 | 
			
		||||
          className="col-span-2"
 | 
			
		||||
          label="Enable scrape"
 | 
			
		||||
          defaultChecked={true}
 | 
			
		||||
          defaultValue={"1"}
 | 
			
		||||
          data={[
 | 
			
		||||
            {
 | 
			
		||||
              label: "Enbale",
 | 
			
		||||
              value: "1",
 | 
			
		||||
            },
 | 
			
		||||
            {
 | 
			
		||||
              label: "Disable",
 | 
			
		||||
              value: "0",
 | 
			
		||||
            },
 | 
			
		||||
          ]}
 | 
			
		||||
          {...form.getInputProps("enable")}
 | 
			
		||||
        />
 | 
			
		||||
        <TextInput
 | 
			
		||||
          className="col-span-2"
 | 
			
		||||
          size="sm"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -35,6 +35,7 @@ export interface IScrapConfig extends ITimestamp {
 | 
			
		|||
  id: number;
 | 
			
		||||
  search_url: string;
 | 
			
		||||
  keywords: string;
 | 
			
		||||
  enable: boolean | "0" | "1";
 | 
			
		||||
  scrap_items: IScrapItem[];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,9 +1,19 @@
 | 
			
		|||
import { IsNumber, IsOptional, IsString, IsUrl } from 'class-validator';
 | 
			
		||||
import {
 | 
			
		||||
  IsBoolean,
 | 
			
		||||
  IsNumber,
 | 
			
		||||
  IsOptional,
 | 
			
		||||
  IsString,
 | 
			
		||||
  IsUrl,
 | 
			
		||||
} from 'class-validator';
 | 
			
		||||
 | 
			
		||||
export class CreateScrapConfigDto {
 | 
			
		||||
  @IsUrl()
 | 
			
		||||
  search_url: string;
 | 
			
		||||
 | 
			
		||||
  @IsBoolean()
 | 
			
		||||
  @IsOptional()
 | 
			
		||||
  enable: boolean;
 | 
			
		||||
 | 
			
		||||
  @IsString()
 | 
			
		||||
  @IsOptional()
 | 
			
		||||
  keywords: string;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -22,6 +22,9 @@ export class ScrapConfig extends Timestamp {
 | 
			
		|||
  @Column({ default: 'cisco' })
 | 
			
		||||
  keywords: string;
 | 
			
		||||
 | 
			
		||||
  @Column({ default: true })
 | 
			
		||||
  enable: boolean;
 | 
			
		||||
 | 
			
		||||
  @OneToOne(() => WebBid, (web) => web.scrap_config, { onDelete: 'CASCADE' })
 | 
			
		||||
  @JoinColumn()
 | 
			
		||||
  web_bid: WebBid;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -16,7 +16,11 @@ export class ScrapConfigsService {
 | 
			
		|||
 | 
			
		||||
  async clientGetScrapeConfigs() {
 | 
			
		||||
    const data = await this.scrapConfigRepo.find({
 | 
			
		||||
      where: { search_url: Not(IsNull()), keywords: Not(IsNull()) },
 | 
			
		||||
      where: {
 | 
			
		||||
        search_url: Not(IsNull()),
 | 
			
		||||
        keywords: Not(IsNull()),
 | 
			
		||||
        enable: true,
 | 
			
		||||
      },
 | 
			
		||||
      relations: {
 | 
			
		||||
        web_bid: true,
 | 
			
		||||
      },
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,7 +14,6 @@ export class TasksService {
 | 
			
		|||
  private readonly logger = new Logger(TasksService.name);
 | 
			
		||||
 | 
			
		||||
  constructor(
 | 
			
		||||
    private readonly scrapConfigsService: ScrapConfigsService,
 | 
			
		||||
    private readonly scrapItemsService: ScrapItemsService,
 | 
			
		||||
    private readonly mailsService: MailsService,
 | 
			
		||||
    private readonly configsSerivce: ConfigsService,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue