(collection *core.Collection)
| 72 | } |
| 73 | |
| 74 | func (p *plugin) jsCreateTemplate(collection *core.Collection) (string, error) { |
| 75 | // unset timestamp fields |
| 76 | collectionData, err := toMap(collection) |
| 77 | if err != nil { |
| 78 | return "", err |
| 79 | } |
| 80 | delete(collectionData, "created") |
| 81 | delete(collectionData, "updated") |
| 82 | deleteNestedMapKey(collectionData, "oauth2", "providers") |
| 83 | |
| 84 | jsonData, err := marhshalWithoutEscape(collectionData, " ", " ") |
| 85 | if err != nil { |
| 86 | return "", fmt.Errorf("failed to serialize collection: %w", err) |
| 87 | } |
| 88 | |
| 89 | const template = jsTypesDirective + `migrate((app) => { |
| 90 | const collection = new Collection(%s); |
| 91 | |
| 92 | return app.save(collection); |
| 93 | }, (app) => { |
| 94 | const collection = app.findCollectionByNameOrId(%q); |
| 95 | |
| 96 | return app.delete(collection); |
| 97 | }) |
| 98 | ` |
| 99 | |
| 100 | return fmt.Sprintf(template, string(jsonData), collection.Id), nil |
| 101 | } |
| 102 | |
| 103 | func (p *plugin) jsDeleteTemplate(collection *core.Collection) (string, error) { |
| 104 | // unset timestamp fields |
no test coverage detected