generated from your-land/yl_template
Implements yl_survey.remove_record
This commit is contained in:
parent
66f4285672
commit
d4cf7d98a6
@ -83,7 +83,7 @@ Returns `true, s_id` if successful, `false, "errormessage` if not.
|
||||
Changes the properties of the survey `s_id` to the values given. `delete_responses` is boolean, optional and defaults to `false`, but if `true` it deletes all prior responses of the survey. See `create_survey` for the other values.
|
||||
|
||||
```
|
||||
yl_survey.remove_survey(s_id)
|
||||
yl_survey.remove_record(s_id)
|
||||
```
|
||||
|
||||
Returns `true, {survey}` if the survey was successfully removed, `false, "errormessage"` otherwise.
|
||||
|
27
api.lua
27
api.lua
@ -199,3 +199,30 @@ function yl_survey.edit_survey(id, owner, allow_names, allow_anonymous,
|
||||
return edit_survey(id, owner, allow_names, allow_anonymous, allow_changes,
|
||||
timestamp_start, timestamp_end, delete_responses)
|
||||
end
|
||||
|
||||
-- yl_survey.remove_record
|
||||
--
|
||||
|
||||
local function remove_record(id)
|
||||
local data_success, data = yl_survey.get_data()
|
||||
if (data_success ~= true) then
|
||||
return false, "Cannot get data"
|
||||
end
|
||||
|
||||
local remove_success = yl_survey.remove_file(id)
|
||||
if (remove_success ~= true) then
|
||||
return false, yl_survey.t("Could not remove")
|
||||
end
|
||||
|
||||
local record = yl_survey.get_record(id)
|
||||
if (record == nil) then
|
||||
return false, yl_survey.t("record not found, cannot remove")
|
||||
end
|
||||
|
||||
data[id] = nil
|
||||
return true, record
|
||||
end
|
||||
|
||||
function yl_survey.remove_record(id)
|
||||
return remove_record(id)
|
||||
end
|
||||
|
@ -129,6 +129,15 @@ function yl_survey.save(filename, content, ...)
|
||||
return save_json(filename, content, ...)
|
||||
end
|
||||
|
||||
-- Remove file
|
||||
|
||||
local function remove_file(UUID)
|
||||
local path = get_filepath(UUID)
|
||||
return os.remove(path)
|
||||
end
|
||||
|
||||
function yl_survey.remove_file(UUID) return remove_file(UUID) end
|
||||
|
||||
-- Load all data
|
||||
--
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user