-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bed4208
commit 8dc8b89
Showing
8 changed files
with
104 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { generate as shortUuid } from 'short-uuid'; | ||
import { IPreset, IPresetCreateDto, IPresetUpdateDto } from '../../common/types/preset'; | ||
import * as Storage from './storage'; | ||
|
||
const FILE_NAME = 'presets.json'; | ||
const presets = new Map<string, IPreset>(); | ||
|
||
const write = async () => { | ||
await Storage.write(FILE_NAME, Array.from(presets.values())); | ||
}; | ||
|
||
export const setup = async () => { | ||
const data = await Storage.read(FILE_NAME, [] as IPreset[]); | ||
data.forEach((preset) => presets.set(preset.id, preset)); | ||
}; | ||
|
||
export const getAll = () => { | ||
return Array.from(presets.values()); | ||
}; | ||
|
||
export const add = async (dto: IPresetCreateDto) => { | ||
let id: string; | ||
do { | ||
id = shortUuid(); | ||
} while (presets.has(id)); | ||
const preset = { | ||
id: id, | ||
name: dto.name, | ||
data: dto.data, | ||
}; | ||
presets.set(id, preset); | ||
await write(); | ||
return preset; | ||
}; | ||
|
||
export const update = async (dto: IPresetUpdateDto) => { | ||
const preset = presets.get(dto.id); | ||
if (!preset) { | ||
return false; | ||
} | ||
presets.set(dto.id, dto); | ||
await write(); | ||
return true; | ||
}; | ||
|
||
export const remove = async (id: string) => { | ||
const removed = presets.delete(id); | ||
if (removed) { | ||
await write(); | ||
} | ||
return removed; | ||
}; | ||
/* | ||
export const getPresets = async () => { | ||
return await Storage.read<IPreset[]>(FILE_NAME, []); | ||
}; | ||
export const writePresets = async (presets: IPreset[]) => { | ||
return await Storage.write(FILE_NAME, presets); | ||
}; | ||
export const setPreset = async (data: IPreset) => { | ||
const presets = await getPresets(); | ||
presets.push(data); | ||
writePresets(presets); | ||
}; | ||
export const deletePreset = async (id: string) => { | ||
const oldPresets = await getPresets(); | ||
const newPresets = oldPresets.filter((preset) => preset.id !== id); | ||
if (oldPresets.length === newPresets.length) { | ||
return false; | ||
} else { | ||
writePresets(newPresets); | ||
return true; | ||
} | ||
}; | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2816,7 +2816,11 @@ | |
} | ||
} | ||
}, | ||
"security": [], | ||
"security": [ | ||
{ | ||
"bearer_token": [] | ||
} | ||
], | ||
"parameters": [] | ||
}, | ||
"post": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters